Re-enabled additional tests

This commit is contained in:
Andrea Boriero 2022-01-05 14:54:06 +01:00 committed by Andrea Boriero
parent dc3b3db512
commit f14e70cb8f
25 changed files with 95 additions and 110 deletions

View File

@ -80,7 +80,9 @@ import org.hibernate.sql.results.graph.FetchParent;
import org.hibernate.sql.results.graph.Fetchable; import org.hibernate.sql.results.graph.Fetchable;
import org.hibernate.sql.results.graph.FetchableContainer; import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult; 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.EntityValuedFetchable;
import org.hibernate.sql.results.graph.entity.internal.EntityResultImpl;
import org.hibernate.sql.results.internal.SqlSelectionImpl; import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl; import org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl;
@ -363,17 +365,12 @@ public class LoaderSelectBuilder {
} }
private SelectStatement generateSelect() { private SelectStatement generateSelect() {
final Restrictable restrictable;
if ( loadable instanceof PluralAttributeMapping ) { if ( loadable instanceof PluralAttributeMapping ) {
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) loadable; final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) loadable;
restrictable = (Restrictable) pluralAttributeMapping.getCollectionDescriptor();
if ( pluralAttributeMapping.getMappedType().getCollectionSemantics() instanceof BagSemantics ) { if ( pluralAttributeMapping.getMappedType().getCollectionSemantics() instanceof BagSemantics ) {
currentBagRole = pluralAttributeMapping.getNavigableRole().getNavigableName(); currentBagRole = pluralAttributeMapping.getNavigableRole().getNavigableName();
} }
} }
else {
restrictable = (Restrictable) loadable;
}
final NavigablePath rootNavigablePath = new NavigablePath( loadable.getRootPathName() ); final NavigablePath rootNavigablePath = new NavigablePath( loadable.getRootPathName() );
@ -738,6 +735,7 @@ public class LoaderSelectBuilder {
boolean explicitFetch = false; boolean explicitFetch = false;
EntityGraphTraversalState.TraversalResult traversalResult = null; EntityGraphTraversalState.TraversalResult traversalResult = null;
final boolean isFetchablePluralAttributeMapping = fetchable instanceof PluralAttributeMapping;
if ( !( fetchable instanceof CollectionPart ) ) { if ( !( fetchable instanceof CollectionPart ) ) {
// 'entity graph' takes precedence over 'fetch profile' // 'entity graph' takes precedence over 'fetch profile'
if ( entityGraphTraversalState != null ) { if ( entityGraphTraversalState != null ) {
@ -774,7 +772,7 @@ public class LoaderSelectBuilder {
if ( cascadeStyle == null || cascadeStyle.doCascade( cascadingAction ) ) { if ( cascadeStyle == null || cascadeStyle.doCascade( cascadingAction ) ) {
fetchTiming = FetchTiming.IMMEDIATE; fetchTiming = FetchTiming.IMMEDIATE;
// In 5.x the CascadeEntityJoinWalker only join fetched the first collection fetch // In 5.x the CascadeEntityJoinWalker only join fetched the first collection fetch
if ( fetchable instanceof PluralAttributeMapping ) { if ( isFetchablePluralAttributeMapping ) {
joined = !hasCollectionJoinFetches; joined = !hasCollectionJoinFetches;
} }
else { else {
@ -786,7 +784,7 @@ public class LoaderSelectBuilder {
final String previousBagRole = currentBagRole; final String previousBagRole = currentBagRole;
final String bagRole; final String bagRole;
if ( fetchable instanceof PluralAttributeMapping if ( isFetchablePluralAttributeMapping
&& ( (PluralAttributeMapping) fetchable ).getMappedType() && ( (PluralAttributeMapping) fetchable ).getMappedType()
.getCollectionSemantics() instanceof BagSemantics ) { .getCollectionSemantics() instanceof BagSemantics ) {
bagRole = fetchable.getNavigableRole().getNavigableName(); bagRole = fetchable.getNavigableRole().getNavigableName();
@ -855,7 +853,7 @@ public class LoaderSelectBuilder {
creationState creationState
); );
if ( fetch.getTiming() == FetchTiming.IMMEDIATE && fetchable instanceof PluralAttributeMapping ) { if ( fetch.getTiming() == FetchTiming.IMMEDIATE && isFetchablePluralAttributeMapping ) {
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable; final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
if ( joined ) { if ( joined ) {
hasCollectionJoinFetches = true; hasCollectionJoinFetches = true;

View File

@ -584,7 +584,6 @@ public class BasicHibernateAnnotationsTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
// @NotImplementedYet(reason = "Support for custom composite types not implemented - org.hibernate.orm.test.annotations.entity.Ransom#getAmount")
public void testCompositeType() throws Exception { public void testCompositeType() throws Exception {
Session s; Session s;
Transaction tx; Transaction tx;

View File

@ -8,6 +8,7 @@ package org.hibernate.orm.test.collection.original;
import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery; import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SessionImplementor;
@ -141,7 +142,12 @@ public class CollectionTest {
scope.inTransaction( scope.inTransaction(
s -> { s -> {
User u2 = findUser( s ); CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
CriteriaQuery<User> criteria = criteriaBuilder.createQuery( User.class );
final Root<User> from = criteria.from( User.class );
from.fetch( "emailAddresses" );
User u2 = s.createQuery( criteria ).uniqueResult();
assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) );
assertFalse( Hibernate.isInitialized( u2.getPermissions() ) ); assertFalse( Hibernate.isInitialized( u2.getPermissions() ) );
assertEquals( 2, u2.getEmailAddresses().size() ); assertEquals( 2, u2.getEmailAddresses().size() );

View File

@ -960,6 +960,7 @@ public class DynamicFilterTest extends BaseNonConfigCoreFunctionalTestCase {
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
CriteriaQuery<Product> criteria = criteriaBuilder.createQuery( Product.class ); CriteriaQuery<Product> criteria = criteriaBuilder.createQuery( Product.class );
Root<Product> root = criteria.from( Product.class ); Root<Product> root = criteria.from( Product.class );
root.fetch( "categories" );
criteria.where( criteriaBuilder.equal( root.get( "id" ), testData.prod1Id ) ); criteria.where( criteriaBuilder.equal( root.get( "id" ), testData.prod1Id ) );
List<Product> result = session.createQuery( criteria ).list(); List<Product> result = session.createQuery( criteria ).list();

View File

@ -6,6 +6,10 @@
*/ */
package org.hibernate.orm.test.mapping.collections.custom.basic; package org.hibernate.orm.test.mapping.collections.custom.basic;
import org.hibernate.Hibernate;
import static org.junit.Assert.assertTrue;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -14,4 +18,9 @@ public class UserCollectionTypeAnnotationsVariantTest extends UserCollectionType
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class[] { User.class, Email.class }; return new Class[] { User.class, Email.class };
} }
@Override
protected void checkEmailAddressInitialization(User user) {
assertTrue( Hibernate.isInitialized( user.getEmailAddresses() ) );
}
} }

View File

@ -6,6 +6,11 @@
*/ */
package org.hibernate.orm.test.mapping.collections.custom.basic; 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 * @author Steve Ebersole
*/ */
@ -19,4 +24,9 @@ public class UserCollectionTypeHbmVariantTest extends UserCollectionTypeTest {
public String[] getMappings() { public String[] getMappings() {
return new String[] { "/org/hibernate/orm/test/mapping/collections/custom/basic/UserPermissions.hbm.xml" }; 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() ) );
}
} }

View File

@ -15,6 +15,7 @@ import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
@ -45,7 +46,7 @@ public abstract class UserCollectionTypeTest extends BaseNonConfigCoreFunctional
criteria.from( User.class ); criteria.from( User.class );
User u2 = s.createQuery( criteria ).uniqueResult(); User u2 = s.createQuery( criteria ).uniqueResult();
// User u2 = (User) s.createCriteria(User.class).uniqueResult(); // User u2 = (User) s.createCriteria(User.class).uniqueResult();
assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); checkEmailAddressInitialization( u2 );
assertEquals( u2.getEmailAddresses().size(), 2 ); assertEquals( u2.getEmailAddresses().size(), 2 );
} }
@ -65,5 +66,7 @@ public abstract class UserCollectionTypeTest extends BaseNonConfigCoreFunctional
); );
} }
protected abstract void checkEmailAddressInitialization(User user);
} }

View File

@ -20,7 +20,7 @@
<class name="User" table="UC_BSC_USER"> <class name="User" table="UC_BSC_USER">
<id name="id"/> <id name="id"/>
<property name="userName"/> <property name="userName"/>
<list name="emailAddresses" fetch="join" lazy="false" cascade="all, delete-orphan" collection-type="MyListType"> <list name="emailAddresses" fetch="join" cascade="all, delete-orphan" collection-type="MyListType">
<key column="userName"/> <key column="userName"/>
<list-index column="displayOrder" base="1"/> <list-index column="displayOrder" base="1"/>
<one-to-many class="Email"/> <one-to-many class="Email"/>

View File

@ -30,6 +30,10 @@
*/ */
package org.hibernate.orm.test.mapping.collections.custom.declaredtype; package org.hibernate.orm.test.mapping.collections.custom.declaredtype;
import org.hibernate.Hibernate;
import static org.junit.Assert.assertTrue;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -38,4 +42,9 @@ public class UserCollectionTypeAnnotationsVariantTest extends UserCollectionType
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class[] { User.class, Email.class }; return new Class[] { User.class, Email.class };
} }
@Override
protected void checkEmailAddressInitialization(User user) {
assertTrue( Hibernate.isInitialized( user.getEmailAddresses() ) );
}
} }

View File

@ -6,6 +6,10 @@
*/ */
package org.hibernate.orm.test.mapping.collections.custom.declaredtype; package org.hibernate.orm.test.mapping.collections.custom.declaredtype;
import org.hibernate.Hibernate;
import static org.junit.Assert.assertFalse;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -14,4 +18,9 @@ public class UserCollectionTypeHbmVariantTest extends UserCollectionTypeTest {
public String[] getMappings() { public String[] getMappings() {
return new String[] { "mapping/collections/custom/declaredtype/UserPermissions.hbm.xml" }; return new String[] { "mapping/collections/custom/declaredtype/UserPermissions.hbm.xml" };
} }
@Override
protected void checkEmailAddressInitialization(User user) {
assertFalse( Hibernate.isInitialized( user.getEmailAddresses() ) );
}
} }

View File

@ -71,12 +71,15 @@ public abstract class UserCollectionTypeTest extends BaseCoreFunctionalTestCase
criteria.from( User.class ); criteria.from( User.class );
User u2 = s.createQuery( criteria ).uniqueResult(); User u2 = s.createQuery( criteria ).uniqueResult();
// User u2 = (User) s.createCriteria(User.class).uniqueResult(); // User u2 = (User) s.createCriteria(User.class).uniqueResult();
assertTrue( Hibernate.isInitialized( u2.getEmailAddresses() ) ); checkEmailAddressInitialization(u2);
assertEquals( u2.getEmailAddresses().size(), 2 ); assertEquals( u2.getEmailAddresses().size(), 2 );
assertNotNull( u2.getEmailAddresses().head()); assertNotNull( u2.getEmailAddresses().head());
} }
); );
} }
protected abstract void checkEmailAddressInitialization(User user);
} }

View File

@ -20,7 +20,7 @@
<class name="User" table="UC_BSC_USER"> <class name="User" table="UC_BSC_USER">
<id name="id"/> <id name="id"/>
<property name="userName"/> <property name="userName"/>
<list name="emailAddresses" fetch="join" lazy="false" cascade="all, delete-orphan" collection-type="HeadListType"> <list name="emailAddresses" fetch="join" cascade="all, delete-orphan" collection-type="HeadListType">
<key column="userName"/> <key column="userName"/>
<list-index column="displayOrder" base="1"/> <list-index column="displayOrder" base="1"/>
<one-to-many class="Email"/> <one-to-many class="Email"/>

View File

@ -45,7 +45,6 @@ import static org.junit.Assert.assertTrue;
xmlMappings = "/mappings/subselectfetch/ParentChild.hbm.xml" xmlMappings = "/mappings/subselectfetch/ParentChild.hbm.xml"
) )
@SessionFactory( useCollectingStatementInspector = true ) @SessionFactory( useCollectingStatementInspector = true )
//@NotImplementedYet( strict = false, reason = "Need to check why these fail" )
public class SubselectFetchTest { public class SubselectFetchTest {
@BeforeEach @BeforeEach
public void prepareTestData(SessionFactoryScope scope) { public void prepareTestData(SessionFactoryScope scope) {

View File

@ -42,7 +42,6 @@ import jakarta.persistence.OneToMany;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected; import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View File

@ -11,7 +11,6 @@ import java.util.List;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;

View File

@ -7,6 +7,7 @@
//$Id: Bid.java 6793 2005-05-16 05:46:47Z oneovthafew $ //$Id: Bid.java 6793 2005-05-16 05:46:47Z oneovthafew $
package org.hibernate.orm.test.query.joinfetch; package org.hibernate.orm.test.query.joinfetch;
import java.util.Calendar; import java.util.Calendar;
/** /**

View File

@ -7,6 +7,7 @@
//$Id: Comment.java 6797 2005-05-16 12:08:03Z oneovthafew $ //$Id: Comment.java 6797 2005-05-16 12:08:03Z oneovthafew $
package org.hibernate.orm.test.query.joinfetch; package org.hibernate.orm.test.query.joinfetch;
import java.util.Calendar; import java.util.Calendar;
/** /**

View File

@ -7,6 +7,7 @@
//$Id: Group.java 7175 2005-06-17 05:23:15Z oneovthafew $ //$Id: Group.java 7175 2005-06-17 05:23:15Z oneovthafew $
package org.hibernate.orm.test.query.joinfetch; package org.hibernate.orm.test.query.joinfetch;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -7,6 +7,7 @@
//$Id: Item.java 6957 2005-05-31 04:21:58Z oneovthafew $ //$Id: Item.java 6957 2005-05-31 04:21:58Z oneovthafew $
package org.hibernate.orm.test.query.joinfetch; package org.hibernate.orm.test.query.joinfetch;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@ -14,9 +14,7 @@
--> -->
<hibernate-mapping <hibernate-mapping package="org.hibernate.orm.test.query.joinfetch" default-access="field">
package="org.hibernate.orm.test.query.joinfetch"
default-access="field">
<class name="Category" table="AuctionCategories"> <class name="Category" table="AuctionCategories">
<id name="name"/> <id name="name"/>

View File

@ -7,21 +7,21 @@
package org.hibernate.orm.test.query.joinfetch; package org.hibernate.orm.test.query.joinfetch;
import java.util.List; import java.util.List;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Root;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope; import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting; import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Root;
import static org.hibernate.cfg.AvailableSettings.MAX_FETCH_DEPTH; import static org.hibernate.cfg.AvailableSettings.MAX_FETCH_DEPTH;
import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE; import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -34,8 +34,8 @@ import static org.junit.Assert.assertTrue;
*/ */
@ServiceRegistry( @ServiceRegistry(
settings = { settings = {
@Setting( name = MAX_FETCH_DEPTH, value = "10" ), @Setting(name = MAX_FETCH_DEPTH, value = "10"),
@Setting( name = USE_SECOND_LEVEL_CACHE, value = "false" ) @Setting(name = USE_SECOND_LEVEL_CACHE, value = "false")
} }
) )
@DomainModel( @DomainModel(
@ -47,27 +47,7 @@ import static org.junit.Assert.assertTrue;
@SessionFactory @SessionFactory
public class JoinFetchTest { public class JoinFetchTest {
// @Test
// public void testProjection() {
// inTransaction(
// s -> {
// CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
// CriteriaQuery<Long> criteria = criteriaBuilder.createQuery( Long.class );
// criteria.select( criteriaBuilder.count( criteria.from( Item.class ) ) );
// s.createQuery( criteria ).uniqueResult();
//
// CriteriaQuery<Item> itemCriteria = criteriaBuilder.createQuery( Item.class );
// itemCriteria.from( Item.class );
// s.createQuery( itemCriteria ).uniqueResult();
//
//// s.createCriteria(Item.class).setProjection( Projections.rowCount() ).uniqueResult();
//// s.createCriteria(Item.class).uniqueResult();
// }
// );
// }
@Test @Test
@NotImplementedYet( strict = false )
public void testJoinFetch(SessionFactoryScope scope) { public void testJoinFetch(SessionFactoryScope scope) {
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
s.createQuery( "delete from Bid" ).executeUpdate(); s.createQuery( "delete from Bid" ).executeUpdate();
@ -93,10 +73,10 @@ public class JoinFetchTest {
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
Item i1 = s.get( Item.class, i.getId() ); Item i1 = s.get( Item.class, i.getId() );
assertTrue( Hibernate.isInitialized( i1.getBids() ) ); assertFalse( Hibernate.isInitialized( i1.getBids() ) );
assertEquals( i1.getBids().size(), 2 ); assertEquals( i1.getBids().size(), 2 );
assertTrue( Hibernate.isInitialized( i1.getComments() ) ); assertFalse( Hibernate.isInitialized( i1.getComments() ) );
assertEquals( i1.getComments().size(), 3 ); assertEquals( 3, i1.getComments().size() );
} ); } );
@ -104,9 +84,9 @@ public class JoinFetchTest {
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
Bid b1 = s.get( Bid.class, b.getId() ); Bid b1 = s.get( Bid.class, b.getId() );
assertTrue( Hibernate.isInitialized( b1.getItem() ) ); assertFalse( Hibernate.isInitialized( b1.getItem() ) );
assertTrue( Hibernate.isInitialized( b1.getItem().getComments() ) ); assertFalse( Hibernate.isInitialized( b1.getItem().getComments() ) );
assertEquals( b1.getItem().getComments().size(), 3 ); assertEquals( 3, b1.getItem().getComments().size() );
} ); } );
scope.getSessionFactory().getCache().evictCollectionData( Item.class.getName() + ".bids" ); scope.getSessionFactory().getCache().evictCollectionData( Item.class.getName() + ".bids" );
@ -131,20 +111,21 @@ public class JoinFetchTest {
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
Item i1 = (Item) s.createQuery( "from Item i left join fetch i.bids left join fetch i.comments" ).uniqueResult(); Item i1 = (Item) s.createQuery( "from Item i left join fetch i.bids left join fetch i.comments" )
.uniqueResult();
assertTrue( Hibernate.isInitialized( i1.getBids() ) ); assertTrue( Hibernate.isInitialized( i1.getBids() ) );
assertTrue( Hibernate.isInitialized( i1.getComments() ) ); assertTrue( Hibernate.isInitialized( i1.getComments() ) );
assertEquals( i1.getComments().size(), 3 ); assertEquals( 3, i1.getComments().size() );
assertEquals( i1.getBids().size(), 2 ); assertEquals( 2, i1.getBids().size() );
} ); } );
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
Item i1 = (Item) ((Object[])s.getNamedQuery( Item.class.getName() + ".all" ).list().get( 0 ))[0]; Item i1 = (Item) s.getNamedQuery( Item.class.getName() + ".all" ).list().get( 0 );
assertTrue( Hibernate.isInitialized( i1.getBids() ) ); assertTrue( Hibernate.isInitialized( i1.getBids() ) );
assertTrue( Hibernate.isInitialized( i1.getComments() ) ); assertTrue( Hibernate.isInitialized( i1.getComments() ) );
assertEquals( i1.getComments().size(), 3 ); assertEquals( 3, i1.getComments().size() );
assertEquals( i1.getBids().size(), 2 ); assertEquals( 2, i1.getBids().size() );
} ); } );
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
@ -154,12 +135,13 @@ public class JoinFetchTest {
Item i1 = s.createQuery( criteria ).uniqueResult(); Item i1 = s.createQuery( criteria ).uniqueResult();
assertFalse( Hibernate.isInitialized( i1.getBids() ) ); assertFalse( Hibernate.isInitialized( i1.getBids() ) );
assertFalse( Hibernate.isInitialized( i1.getComments() ) ); assertFalse( Hibernate.isInitialized( i1.getComments() ) );
assertEquals( i1.getComments().size(), 3 ); assertEquals( 3, i1.getComments().size() );
assertEquals( i1.getBids().size(), 2 ); assertEquals( 2, i1.getBids().size() );
} ); } );
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
List bids = s.createQuery( "select b from Bid b left join fetch b.item i left join fetch i.category" ).list(); List bids = s.createQuery( "select b from Bid b left join fetch b.item i left join fetch i.category" )
.list();
Bid bid = (Bid) bids.get( 0 ); Bid bid = (Bid) bids.get( 0 );
assertTrue( Hibernate.isInitialized( bid.getItem() ) ); assertTrue( Hibernate.isInitialized( bid.getItem() ) );
assertTrue( Hibernate.isInitialized( bid.getItem().getCategory() ) ); assertTrue( Hibernate.isInitialized( bid.getItem().getCategory() ) );
@ -172,7 +154,7 @@ public class JoinFetchTest {
assertTrue( Hibernate.isInitialized( item.getCategory() ) ); assertTrue( Hibernate.isInitialized( item.getCategory() ) );
s.clear(); s.clear();
pairs = s.createQuery( "select i, b from Item i left join i.bids b left join i.category" ).list(); pairs = s.createQuery( "select i, b from Item i left join i.bids b left join i.category" ).list();
item = (Item) ((Object[])pairs.get( 0 ))[0]; item = (Item) ( (Object[]) pairs.get( 0 ) )[0];
assertFalse( Hibernate.isInitialized( item.getBids() ) ); assertFalse( Hibernate.isInitialized( item.getBids() ) );
assertFalse( Hibernate.isInitialized( item.getCategory() ) ); assertFalse( Hibernate.isInitialized( item.getCategory() ) );
s.clear(); s.clear();
@ -191,7 +173,7 @@ public class JoinFetchTest {
assertTrue( Hibernate.isInitialized( bid.getItem() ) ); assertTrue( Hibernate.isInitialized( bid.getItem() ) );
assertFalse( Hibernate.isInitialized( bid.getItem().getCategory() ) ); assertFalse( Hibernate.isInitialized( bid.getItem().getCategory() ) );
pairs = s.createQuery( "select b from Bid b left join b.item i left join i.category" ).list(); pairs = s.createQuery( "select b from Bid b left join b.item i left join i.category" ).list();
bid = (Bid) pairs.get( 0 ) ; bid = (Bid) pairs.get( 0 );
assertTrue( Hibernate.isInitialized( bid.getItem() ) ); assertTrue( Hibernate.isInitialized( bid.getItem() ) );
assertFalse( Hibernate.isInitialized( bid.getItem().getCategory() ) ); assertFalse( Hibernate.isInitialized( bid.getItem().getCategory() ) );
} ); } );
@ -204,45 +186,7 @@ public class JoinFetchTest {
} ); } );
} }
// @Test
// public void testCollectionFilter() {
// inTransaction(
// s -> {
// Group hb = new Group( "hibernate" );
// User gavin = new User( "gavin" );
// User max = new User( "max" );
// hb.getUsers().put( "gavin", gavin );
// hb.getUsers().put( "max", max );
// gavin.getGroups().put( "hibernate", hb );
// max.getGroups().put( "hibernate", hb );
// s.persist( hb );
// }
// );
//
// inTransaction(
// s -> {
// CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder();
// CriteriaQuery<Group> criteria = criteriaBuilder.createQuery( Group.class );
// Root<Group> from = criteria.from( Group.class );
//// from.join( "users", JoinType.LEFT );
// criteria.where( criteriaBuilder.equal( from.get( "name" ), "hibernate" ) );
// Group hb = s.createQuery( criteria ).uniqueResult();
//// hb = (Group) s.createCriteria( Group.class )
//// .setFetchMode( "users", FetchMode.SELECT )
//// .add( Restrictions.idEq( "hibernate" ) )
//// .uniqueResult();
//// assertFalse( Hibernate.isInitialized( hb.getUsers() ) );
//// gavin = (User) s.createFilter( hb.getUsers(), "where index(this) = 'gavin'" ).uniqueResult();
//// Long size = (Long) s.createFilter( hb.getUsers(), "select count(*)" ).uniqueResult();
//// assertEquals( new Long( 2 ), size );
//// assertFalse( Hibernate.isInitialized( hb.getUsers() ) );
// s.delete( hb );
// }
// );
// }
@Test @Test
@NotImplementedYet( strict = false )
public void testJoinFetchManyToMany(SessionFactoryScope scope) { public void testJoinFetchManyToMany(SessionFactoryScope scope) {
Group group = new Group( "hibernate" ); Group group = new Group( "hibernate" );
@ -258,7 +202,7 @@ public class JoinFetchTest {
scope.inTransaction( (s) -> { scope.inTransaction( (s) -> {
Group hb = s.get( Group.class, "hibernate" ); Group hb = s.get( Group.class, "hibernate" );
assertTrue( Hibernate.isInitialized( hb.getUsers() ) ); assertFalse( Hibernate.isInitialized( hb.getUsers() ) );
User gavin = (User) hb.getUsers().get( "gavin" ); User gavin = (User) hb.getUsers().get( "gavin" );
assertFalse( Hibernate.isInitialized( gavin.getGroups() ) ); assertFalse( Hibernate.isInitialized( gavin.getGroups() ) );
User max = s.get( User.class, "max" ); User max = s.get( User.class, "max" );

View File

@ -7,6 +7,7 @@
//$Id: User.java 7175 2005-06-17 05:23:15Z oneovthafew $ //$Id: User.java 7175 2005-06-17 05:23:15Z oneovthafew $
package org.hibernate.orm.test.query.joinfetch; package org.hibernate.orm.test.query.joinfetch;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -14,9 +14,7 @@
--> -->
<hibernate-mapping <hibernate-mapping package="org.hibernate.orm.test.query.joinfetch" default-access="field">
package="org.hibernate.orm.test.query.joinfetch"
default-access="field">
<class name="User" table="AuctionUsers"> <class name="User" table="AuctionUsers">
<id name="name"/> <id name="name"/>

View File

@ -23,7 +23,6 @@ import org.hibernate.query.Query;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey; import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.RequiresDialect; import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;
@ -49,8 +48,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
) )
@SessionFactory( useCollectingStatementInspector = true ) @SessionFactory( useCollectingStatementInspector = true )
@RequiresDialect(AbstractHANADialect.class) @RequiresDialect(AbstractHANADialect.class)
// afaik this does not work
//@NotImplementedYet( strict = false )
public class QueryHintHANATest { public class QueryHintHANATest {
@BeforeEach @BeforeEach

View File

@ -14,7 +14,6 @@ import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.jdbc.SQLStatementInspector; import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneSelfReference; import org.hibernate.testing.orm.domain.gambit.EntityWithManyToOneSelfReference;
import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.NotImplementedYet; import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.ServiceRegistry; import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactory;