From f14e70cb8f0057b4d6830e7de60dd3802904dc19 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 5 Jan 2022 14:54:06 +0100 Subject: [PATCH] Re-enabled additional tests --- .../ast/internal/LoaderSelectBuilder.java | 14 +-- .../entity/BasicHibernateAnnotationsTest.java | 1 - .../collection/original/CollectionTest.java | 8 +- .../orm/test/filter/DynamicFilterTest.java | 1 + ...rCollectionTypeAnnotationsVariantTest.java | 9 ++ .../UserCollectionTypeHbmVariantTest.java | 10 ++ .../custom/basic/UserCollectionTypeTest.java | 5 +- .../custom/basic/UserPermissions.hbm.xml | 2 +- ...rCollectionTypeAnnotationsVariantTest.java | 9 ++ .../UserCollectionTypeHbmVariantTest.java | 9 ++ .../declaredtype/UserCollectionTypeTest.java | 5 +- .../declaredtype/UserPermissions.hbm.xml | 2 +- .../fetch/subselect/SubselectFetchTest.java | 1 - .../discriminator/JoinedInheritanceTest.java | 1 - .../typedmanytoone/TypedManyToOneTest.java | 1 - .../orm/test/query/joinfetch/Bid.java | 1 + .../orm/test/query/joinfetch/Comment.java | 1 + .../orm/test/query/joinfetch/Group.java | 1 + .../orm/test/query/joinfetch/Item.java | 1 + .../orm/test/query/joinfetch/ItemBid.hbm.xml | 4 +- .../test/query/joinfetch/JoinFetchTest.java | 110 +++++------------- .../orm/test/query/joinfetch/User.java | 1 + .../test/query/joinfetch/UserGroup.hbm.xml | 4 +- .../orm/test/queryhint/QueryHintHANATest.java | 3 - .../EntityWithManyToOneSelfReferenceTest.java | 1 - 25 files changed, 95 insertions(+), 110 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java index e2090c37d2..325d5aa8aa 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderSelectBuilder.java @@ -80,7 +80,9 @@ import org.hibernate.sql.results.graph.FetchParent; import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.FetchableContainer; import org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult; +import org.hibernate.sql.results.graph.collection.internal.CollectionFetch; import org.hibernate.sql.results.graph.entity.EntityValuedFetchable; +import org.hibernate.sql.results.graph.entity.internal.EntityResultImpl; import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl; @@ -363,17 +365,12 @@ public class LoaderSelectBuilder { } private SelectStatement generateSelect() { - final Restrictable restrictable; if ( loadable instanceof PluralAttributeMapping ) { final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) loadable; - restrictable = (Restrictable) pluralAttributeMapping.getCollectionDescriptor(); if ( pluralAttributeMapping.getMappedType().getCollectionSemantics() instanceof BagSemantics ) { currentBagRole = pluralAttributeMapping.getNavigableRole().getNavigableName(); } } - else { - restrictable = (Restrictable) loadable; - } final NavigablePath rootNavigablePath = new NavigablePath( loadable.getRootPathName() ); @@ -738,6 +735,7 @@ public class LoaderSelectBuilder { boolean explicitFetch = false; EntityGraphTraversalState.TraversalResult traversalResult = null; + final boolean isFetchablePluralAttributeMapping = fetchable instanceof PluralAttributeMapping; if ( !( fetchable instanceof CollectionPart ) ) { // 'entity graph' takes precedence over 'fetch profile' if ( entityGraphTraversalState != null ) { @@ -774,7 +772,7 @@ public class LoaderSelectBuilder { if ( cascadeStyle == null || cascadeStyle.doCascade( cascadingAction ) ) { fetchTiming = FetchTiming.IMMEDIATE; // In 5.x the CascadeEntityJoinWalker only join fetched the first collection fetch - if ( fetchable instanceof PluralAttributeMapping ) { + if ( isFetchablePluralAttributeMapping ) { joined = !hasCollectionJoinFetches; } else { @@ -786,7 +784,7 @@ public class LoaderSelectBuilder { final String previousBagRole = currentBagRole; final String bagRole; - if ( fetchable instanceof PluralAttributeMapping + if ( isFetchablePluralAttributeMapping && ( (PluralAttributeMapping) fetchable ).getMappedType() .getCollectionSemantics() instanceof BagSemantics ) { bagRole = fetchable.getNavigableRole().getNavigableName(); @@ -855,7 +853,7 @@ public class LoaderSelectBuilder { creationState ); - if ( fetch.getTiming() == FetchTiming.IMMEDIATE && fetchable instanceof PluralAttributeMapping ) { + if ( fetch.getTiming() == FetchTiming.IMMEDIATE && isFetchablePluralAttributeMapping ) { final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable; if ( joined ) { hasCollectionJoinFetches = true; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/BasicHibernateAnnotationsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/BasicHibernateAnnotationsTest.java index e2adec423e..1849b818dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/BasicHibernateAnnotationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/entity/BasicHibernateAnnotationsTest.java @@ -584,7 +584,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase { } @Test -// @NotImplementedYet(reason = "Support for custom composite types not implemented - org.hibernate.orm.test.annotations.entity.Ransom#getAmount") public void testCompositeType() throws Exception { Session s; Transaction tx; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/original/CollectionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/original/CollectionTest.java index 318fc5defd..ff1e1444c2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/collection/original/CollectionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/collection/original/CollectionTest.java @@ -8,6 +8,7 @@ package org.hibernate.orm.test.collection.original; import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Root; import org.hibernate.Hibernate; import org.hibernate.engine.spi.SessionImplementor; @@ -141,7 +142,12 @@ public class CollectionTest { scope.inTransaction( s -> { - User u2 = findUser( s ); + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( User.class ); + final Root from = criteria.from( User.class ); + from.fetch( "emailAddresses" ); + + User u2 = s.createQuery( criteria ).uniqueResult(); assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); assertFalse( Hibernate.isInitialized( u2.getPermissions() ) ); assertEquals( 2, u2.getEmailAddresses().size() ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/filter/DynamicFilterTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/filter/DynamicFilterTest.java index f0bb6c3b87..90247a7e1f 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/filter/DynamicFilterTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/filter/DynamicFilterTest.java @@ -960,6 +960,7 @@ public class DynamicFilterTest extends BaseNonConfigCoreFunctionalTestCase { CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); CriteriaQuery criteria = criteriaBuilder.createQuery( Product.class ); Root root = criteria.from( Product.class ); + root.fetch( "categories" ); criteria.where( criteriaBuilder.equal( root.get( "id" ), testData.prod1Id ) ); List result = session.createQuery( criteria ).list(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeAnnotationsVariantTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeAnnotationsVariantTest.java index 8fd6c6a168..58080a2859 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeAnnotationsVariantTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeAnnotationsVariantTest.java @@ -6,6 +6,10 @@ */ package org.hibernate.orm.test.mapping.collections.custom.basic; +import org.hibernate.Hibernate; + +import static org.junit.Assert.assertTrue; + /** * @author Steve Ebersole */ @@ -14,4 +18,9 @@ public class UserCollectionTypeAnnotationsVariantTest extends UserCollectionType protected Class[] getAnnotatedClasses() { return new Class[] { User.class, Email.class }; } + + @Override + protected void checkEmailAddressInitialization(User user) { + assertTrue( Hibernate.isInitialized( user.getEmailAddresses() ) ); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeHbmVariantTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeHbmVariantTest.java index 4641791e54..635025066e 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeHbmVariantTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeHbmVariantTest.java @@ -6,6 +6,11 @@ */ package org.hibernate.orm.test.mapping.collections.custom.basic; +import org.hibernate.Hibernate; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Steve Ebersole */ @@ -19,4 +24,9 @@ public class UserCollectionTypeHbmVariantTest extends UserCollectionTypeTest { public String[] getMappings() { return new String[] { "/org/hibernate/orm/test/mapping/collections/custom/basic/UserPermissions.hbm.xml" }; } + + @Override + protected void checkEmailAddressInitialization(User user) { + assertFalse( Hibernate.isInitialized( user.getEmailAddresses() ) ); + } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeTest.java index 5e8ec613d3..31af80c617 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserCollectionTypeTest.java @@ -15,6 +15,7 @@ import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** @@ -45,7 +46,7 @@ public abstract class UserCollectionTypeTest extends BaseNonConfigCoreFunctional criteria.from( User.class ); User u2 = s.createQuery( criteria ).uniqueResult(); // User u2 = (User) s.createCriteria(User.class).uniqueResult(); - assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); + checkEmailAddressInitialization( u2 ); assertEquals( u2.getEmailAddresses().size(), 2 ); } @@ -65,5 +66,7 @@ public abstract class UserCollectionTypeTest extends BaseNonConfigCoreFunctional ); } + protected abstract void checkEmailAddressInitialization(User user); + } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserPermissions.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserPermissions.hbm.xml index 4e75a543e2..d225834939 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserPermissions.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/mapping/collections/custom/basic/UserPermissions.hbm.xml @@ -20,7 +20,7 @@ - +