diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java index 7febd4a1ea82..64ca93db79ec 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java @@ -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; @@ -576,7 +575,7 @@ private void startIfNeeded() { if ( active ) { return; } - executorService = Executors.newSingleThreadScheduledExecutor( new ValidationThreadFactory() ); + executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleWithFixedDelay( this, validationInterval, @@ -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; - } - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java index 327976f8c72c..d0e9f320449f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/QuerySplitter.java @@ -38,8 +38,8 @@ public static SqmSelectStatement[] split(SqmSelectStatement statement) return sqmSelectStatement; } - final SqmPolymorphicRootDescriptor unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor) unmappedPolymorphicReference.getReferencedPathSource(); - final Set> implementors = unmappedPolymorphicDescriptor.getImplementors(); + final SqmPolymorphicRootDescriptor unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor) unmappedPolymorphicReference.getReferencedPathSource(); + final Set> implementors = unmappedPolymorphicDescriptor.getImplementors(); @SuppressWarnings("unchecked") final SqmSelectStatement[] expanded = new SqmSelectStatement[ implementors.size() ]; @@ -105,8 +105,8 @@ public static SqmDeleteStatement[] split(SqmDeleteStatement statement) return sqmDeleteStatement; } - final SqmPolymorphicRootDescriptor unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor) unmappedPolymorphicReference.getReferencedPathSource(); - final Set> implementors = unmappedPolymorphicDescriptor.getImplementors(); + final SqmPolymorphicRootDescriptor unmappedPolymorphicDescriptor = (SqmPolymorphicRootDescriptor) unmappedPolymorphicReference.getReferencedPathSource(); + final Set> implementors = unmappedPolymorphicDescriptor.getImplementors(); @SuppressWarnings("unchecked") final SqmDeleteStatement[] expanded = new SqmDeleteStatement[ implementors.size() ]; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java index a0e7570b7801..d40c256f2024 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPolymorphicRootDescriptor.java @@ -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. @@ -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 ) ); } @@ -120,8 +117,8 @@ private static boolean isACommonAttribute(List> subList, Per return true; } - public Set> getImplementors() { - return implementors; + public Set> getImplementors() { + return new HashSet<>( implementors ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/connection/DriverManagerConnectionProviderValidationConfigTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/connection/DriverManagerConnectionProviderValidationConfigTest.java deleted file mode 100644 index 7b9d12b8980b..000000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/connection/DriverManagerConnectionProviderValidationConfigTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SPDX-License-Identifier: LGPL-2.1-or-later - * Copyright Red Hat Inc. and Hibernate Authors - */ -package org.hibernate.orm.test.connection; - -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; - -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; - -import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; -import org.hibernate.testing.orm.junit.Jpa; -import org.hibernate.testing.orm.junit.Setting; - -import org.junit.jupiter.api.Test; - -import static org.junit.Assert.assertTrue; - -/** - * @author Vlad Mihalcea - */ -@Jpa( - annotatedClasses = { DriverManagerConnectionProviderValidationConfigTest.Event.class }, - integrationSettings = { - // Force a non-shared connection provider to avoid re-creation of the shared pool - @Setting(name = AvailableSettings.CONNECTION_PROVIDER, value = ""), - @Setting(name = DriverManagerConnectionProviderImpl.VALIDATION_INTERVAL, value = "1") - } -) -public class DriverManagerConnectionProviderValidationConfigTest { - - @Test - public void test(EntityManagerFactoryScope scope) { - scope.inTransaction( - entityManager -> { - Event event = new Event(); - entityManager.persist( event ); - - assertTrue( Thread.getAllStackTraces() - .keySet() - .stream() - .filter( thread -> thread.getName() - .equals( "Hibernate Connection Pool Validation Thread" ) && thread.isDaemon() ) - .map( Thread::isDaemon ) - .findAny() - .isPresent() ); - } - ); - } - - @Entity(name = "Event") - public static class Event { - - @Id - @GeneratedValue - private Long id; - - private String name; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/EntityGraphUsingFetchGraphTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/EntityGraphUsingFetchGraphTest.java index dfc79c09069d..d36fb027afb1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/EntityGraphUsingFetchGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/EntityGraphUsingFetchGraphTest.java @@ -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; @@ -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; @@ -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; /** @@ -143,68 +138,6 @@ void fetchAttributeNodeByStringFromSubgraph(SessionFactoryScope scope) { query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph ); final List 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 entityGraph = em.createEntityGraph( CustomerOrder.class ); - EntityType customerOrderEntityType = - scope.getSessionFactory().getMetamodel().entity( CustomerOrder.class ); - entityGraph.addAttributeNodes( - customerOrderEntityType.getAttribute( "shippingAddress" ), - customerOrderEntityType.getAttribute( "orderDate" ) - ); - entityGraph.addAttributeNodes( customerOrderEntityType.getAttribute( "shippingAddress" ) ); - - final Subgraph orderProductsSubgraph = - entityGraph.addSubgraph( (Attribute) customerOrderEntityType.getAttribute( "orderPosition" ) ); - EntityType positionEntityType = - scope.getSessionFactory().getMetamodel().entity( OrderPosition.class ); - orderProductsSubgraph.addAttributeNodes( positionEntityType.getAttribute( "amount" ) ); - orderProductsSubgraph.addAttributeNodes( positionEntityType.getAttribute( "product" ) ); - - final Subgraph productSubgraph = - orderProductsSubgraph.addSubgraph( (Attribute) positionEntityType.getAttribute( "product" ) ); - EntityType productEntityType = scope.getSessionFactory().getMetamodel().entity( Product.class ); - productSubgraph.addAttributeNodes( productEntityType.getAttribute( "productName" ) ); - - TypedQuery query = em.createQuery( - "SELECT o FROM CustomerOrder o", CustomerOrder.class - ); - query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph ); - final List results = query.getResultList(); - - assertEntityGraph( entityGraph ); assertThat( results, isInitialized() ); } ); @@ -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 entityGraph) { - assertThat(entityGraph.getAttributeNodes(), hasSize( 3 ) ); - for ( AttributeNode entityGraphAttributeNode : entityGraph.getAttributeNodes() ) { - if ( "orderPosition".equals( entityGraphAttributeNode.getAttributeName() ) ) { - Collection orderPositionGraph = entityGraphAttributeNode.getSubgraphs().values(); - assertThat( orderPositionGraph, hasSize( 1 ) ); - List> 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 { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NamedQueryTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NamedQueryTest.java index 8b1a973eae60..6acced1ad4a6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NamedQueryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/query/NamedQueryTest.java @@ -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 @@ -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() { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest.java index 598cee2dec80..688963b159f9 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/polymorphic/PolymorphicQueriesTest.java @@ -64,8 +64,6 @@ public void testQuery(SessionFactoryScope scope) { session -> { List 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); } ); @@ -73,8 +71,6 @@ public void testQuery(SessionFactoryScope scope) { session -> { List 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); } ); @@ -83,8 +79,6 @@ public void testQuery(SessionFactoryScope scope) { List 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); } ); }