Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -576,7 +575,7 @@ private void startIfNeeded() {
if ( active ) {
return;
}
executorService = Executors.newSingleThreadScheduledExecutor( new ValidationThreadFactory() );
executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(
this,
validationInterval,
Expand Down Expand Up @@ -683,14 +682,4 @@ else if ( e != null ) {
}
}

private static class ValidationThreadFactory implements ThreadFactory {
@Override
public Thread newThread(Runnable runnable) {
final Thread thread = new Thread( runnable );
thread.setDaemon( true );
thread.setName( "Hibernate Connection Pool Validation Thread" );
return thread;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static <R> SqmSelectStatement<R>[] split(SqmSelectStatement<R> statement)
return sqmSelectStatement;
}

final SqmPolymorphicRootDescriptor<R> unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor<R>) unmappedPolymorphicReference.getReferencedPathSource();
final Set<EntityDomainType<? extends R>> implementors = unmappedPolymorphicDescriptor.getImplementors();
final SqmPolymorphicRootDescriptor<?> unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor<?>) unmappedPolymorphicReference.getReferencedPathSource();
final Set<EntityDomainType<?>> implementors = unmappedPolymorphicDescriptor.getImplementors();
@SuppressWarnings("unchecked")
final SqmSelectStatement<R>[] expanded = new SqmSelectStatement[ implementors.size() ];

Expand Down Expand Up @@ -105,8 +105,8 @@ public static <R> SqmDeleteStatement<R>[] split(SqmDeleteStatement<R> statement)
return sqmDeleteStatement;
}

final SqmPolymorphicRootDescriptor<R> unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor<R>) unmappedPolymorphicReference.getReferencedPathSource();
final Set<EntityDomainType<? extends R>> implementors = unmappedPolymorphicDescriptor.getImplementors();
final SqmPolymorphicRootDescriptor<?> unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor<?>) unmappedPolymorphicReference.getReferencedPathSource();
final Set<EntityDomainType<?>> implementors = unmappedPolymorphicDescriptor.getImplementors();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn’t say that we need to roll back such trivial things.

Copy link
Member

@sebersole sebersole Mar 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, I would not necessarily say it is trivial. But I do think it is questionable whether the change is obvious and self-evident. I think given the request, this is how any of us would have implemented it.

And in fact, @beikov contributed much to the actual implementation - #7468 (comment)

Let's roll back this removal

@SuppressWarnings("unchecked")
final SqmDeleteStatement<R>[] expanded = new SqmDeleteStatement[ implementors.size() ];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;

import static java.util.Collections.unmodifiableMap;
import static java.util.Comparator.comparing;

/**
* Acts as the {@link EntityDomainType} for a "polymorphic query" grouping.
Expand All @@ -56,8 +54,7 @@ public SqmPolymorphicRootDescriptor(
JpaMetamodel jpaMetamodel) {
this.polymorphicJavaType = polymorphicJavaType;
this.jpaMetamodel = jpaMetamodel;
this.implementors = new TreeSet<>( comparing(EntityDomainType::getTypeName) );
this.implementors.addAll( implementors );
this.implementors = implementors;
this.commonAttributes = unmodifiableMap( inferCommonAttributes( implementors ) );
}

Expand Down Expand Up @@ -120,8 +117,8 @@ private static boolean isACommonAttribute(List<EntityDomainType<?>> subList, Per
return true;
}

public Set<EntityDomainType<? extends T>> getImplementors() {
return implementors;
public Set<EntityDomainType<?>> getImplementors() {
return new HashSet<>( implementors );
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
*/
package org.hibernate.orm.test.entitygraph;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import jakarta.persistence.AttributeNode;

import jakarta.persistence.Entity;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
Expand All @@ -21,8 +20,6 @@
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.persistence.TypedQuery;
import jakarta.persistence.metamodel.Attribute;
import jakarta.persistence.metamodel.EntityType;

import org.hibernate.graph.GraphSemantic;

Expand All @@ -32,9 +29,7 @@
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize;
import static org.hibernate.testing.hamcrest.InitializationCheckMatcher.isInitialized;

/**
Expand Down Expand Up @@ -143,68 +138,6 @@ void fetchAttributeNodeByStringFromSubgraph(SessionFactoryScope scope) {
query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph );
final List<CustomerOrder> results = query.getResultList();

assertEntityGraph( entityGraph );
assertThat( results, isInitialized() );
}
);
}

@Test
@JiraKey( value = "HHH-13233")
@SuppressWarnings({ "unchecked", "rawtypes" })
void fetchAttributeNodeByAttributeFromSubgraph(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Address address = new Address();
address.city = "TestCity";

CustomerOrder customerOrder = new CustomerOrder();
customerOrder.shippingAddress = address;

Product product = new Product();

OrderPosition orderPosition = new OrderPosition();
orderPosition.product = product;

customerOrder.orderPosition = orderPosition;
session.persist( address );
session.persist( orderPosition );
session.persist( product );
session.persist( customerOrder );
}
);

scope.inTransaction(
session -> {
final EntityManager em = session.unwrap( EntityManager.class );
final EntityGraph<CustomerOrder> entityGraph = em.createEntityGraph( CustomerOrder.class );
EntityType<CustomerOrder> customerOrderEntityType =
scope.getSessionFactory().getMetamodel().entity( CustomerOrder.class );
entityGraph.addAttributeNodes(
customerOrderEntityType.getAttribute( "shippingAddress" ),
customerOrderEntityType.getAttribute( "orderDate" )
);
entityGraph.addAttributeNodes( customerOrderEntityType.getAttribute( "shippingAddress" ) );

final Subgraph<OrderPosition> orderProductsSubgraph =
entityGraph.addSubgraph( (Attribute) customerOrderEntityType.getAttribute( "orderPosition" ) );
EntityType<OrderPosition> positionEntityType =
scope.getSessionFactory().getMetamodel().entity( OrderPosition.class );
orderProductsSubgraph.addAttributeNodes( positionEntityType.getAttribute( "amount" ) );
orderProductsSubgraph.addAttributeNodes( positionEntityType.getAttribute( "product" ) );

final Subgraph<Product> productSubgraph =
orderProductsSubgraph.addSubgraph( (Attribute) positionEntityType.getAttribute( "product" ) );
EntityType<Product> productEntityType = scope.getSessionFactory().getMetamodel().entity( Product.class );
productSubgraph.addAttributeNodes( productEntityType.getAttribute( "productName" ) );

TypedQuery<CustomerOrder> query = em.createQuery(
"SELECT o FROM CustomerOrder o", CustomerOrder.class
);
query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph );
final List<CustomerOrder> results = query.getResultList();

assertEntityGraph( entityGraph );
assertThat( results, isInitialized() );
}
);
Expand Down Expand Up @@ -250,37 +183,6 @@ void fetchUsingHql(SessionFactoryScope scope) {
);
}

/**
* Verify that entityGraph has expected state
*
* customerOrder - shippingAddress
* - orderDate
* - orderPosition - amount
* - product - productName
*
* @param entityGraph entityGraph
*/
private void assertEntityGraph(EntityGraph<CustomerOrder> entityGraph) {
assertThat(entityGraph.getAttributeNodes(), hasSize( 3 ) );
for ( AttributeNode<?> entityGraphAttributeNode : entityGraph.getAttributeNodes() ) {
if ( "orderPosition".equals( entityGraphAttributeNode.getAttributeName() ) ) {
Collection<Subgraph> orderPositionGraph = entityGraphAttributeNode.getSubgraphs().values();
assertThat( orderPositionGraph, hasSize( 1 ) );
List<AttributeNode<?>> orderPositionAttributes = orderPositionGraph.iterator().next().getAttributeNodes();
assertThat( orderPositionAttributes, hasSize( 2 ) );
for ( AttributeNode<?> orderPositionAttributeNode : orderPositionAttributes ) {
if ( "product".equals( orderPositionAttributeNode.getAttributeName() ) ) {
assertThat( orderPositionAttributeNode.getSubgraphs().entrySet(), hasSize( 1 ) );
} else {
assertThat( orderPositionAttributeNode.getSubgraphs().isEmpty(), is( true ) );
}
}
} else {
assertThat( entityGraphAttributeNode.getSubgraphs().isEmpty(), is( true ) );
}
}
}

@Entity(name = "CustomerOrder")
@Table(name = "customerOrder")
public static class CustomerOrder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

/**
* @author Andrea Boriero
Expand Down Expand Up @@ -180,18 +179,6 @@ public void testNativeQueriesFromNamedQueriesDoNotShareQuerySpaces() {
} );
}

@Test
@JiraKey(value = "HHH-11413")
public void testNamedNativeQueryExceptionNoResultDefined() {
doInJPA( this::entityManagerFactory, entityManager -> {
assertThrows(
"Named query exists but its result type is not compatible",
IllegalArgumentException.class,
() -> entityManager.createNamedQuery( "NamedNativeQuery", Game.class )
);
} );
}

@Test
@JiraKey(value = "HHH-11413")
public void testNamedQueryAddedFromTypedNativeQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,13 @@ public void testQuery(SessionFactoryScope scope) {
session -> {
List<I> results = session.createQuery( "from " + I.class.getName(), I.class ).list();
assertThat( results.size() ).isEqualTo( 2 );
assertThat(results.get(0)).isInstanceOf(EntityA.class);
assertThat(results.get(1)).isInstanceOf(EntityB.class);
}
);

scope.inTransaction(
session -> {
List<I> results = session.createQuery( "from " + I.class.getName() + " i", I.class ).list();
assertThat( results.size() ).isEqualTo( 2 );
assertThat(results.get(0)).isInstanceOf(EntityA.class);
assertThat(results.get(1)).isInstanceOf(EntityB.class);
}
);

Expand All @@ -83,8 +79,6 @@ public void testQuery(SessionFactoryScope scope) {
List<I> results = session.createQuery( "select i from " + I.class.getName() + " i", I.class )
.list();
assertThat( results.size() ).isEqualTo( 2 );
assertThat(results.get(0)).isInstanceOf(EntityA.class);
assertThat(results.get(1)).isInstanceOf(EntityB.class);
}
);
}
Expand Down
Loading