diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/CachedPropertyRefCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/CachedPropertyRefCollectionTest.java new file mode 100644 index 0000000000..c30ebe15da --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/CachedPropertyRefCollectionTest.java @@ -0,0 +1,80 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.orm.test.propertyref.cachedcollections; + +import org.hibernate.Hibernate; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Set of tests originally developed to verify and fix HHH-5853 + * + * @author Steve Ebersole + */ +@TestForIssue(jiraKey = "HHH-5853") +@DomainModel( + xmlMappings = "org/hibernate/orm/test/propertyref/cachedcollections/Mappings.hbm.xml" +) +@SessionFactory +public class CachedPropertyRefCollectionTest { + + private ManagedObject mo; + + @BeforeEach + public void setUp(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + mo = new ManagedObject( "test", "test" ); + mo.getMembers().add( "members" ); + session.save( mo ); + } + ); + } + + @AfterEach + public void tearDown(SessionFactoryScope scope) { + scope.inTransaction( + session -> + session.delete( mo ) + ); + } + + @Test + public void testRetrievalOfCachedCollectionWithPropertyRefKey(SessionFactoryScope scope) { + // First attempt to load it via PK lookup + scope.inTransaction( + session -> { + ManagedObject obj = session.get( ManagedObject.class, 1L ); + assertNotNull( obj ); + assertTrue( Hibernate.isInitialized( obj ) ); + obj.getMembers().size(); + assertTrue( Hibernate.isInitialized( obj.getMembers() ) ); + } + ); + + // Now try to access it via natural key + scope.inTransaction( + session -> { + ManagedObject obj = session.bySimpleNaturalId( ManagedObject.class ).load( "test" ); + assertNotNull( obj ); + assertTrue( Hibernate.isInitialized( obj ) ); + obj.getMembers().size(); + assertTrue( Hibernate.isInitialized( obj.getMembers() ) ); + } + ); + } +} + diff --git a/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/ManagedObject.java b/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/ManagedObject.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/ManagedObject.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/ManagedObject.java index cd1fd00773..22a2c52078 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/ManagedObject.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/ManagedObject.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.propertyref.cachedcollections; +package org.hibernate.orm.test.propertyref.cachedcollections; import java.util.HashSet; import java.util.Set; diff --git a/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/Mappings.hbm.xml b/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/Mappings.hbm.xml similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/Mappings.hbm.xml rename to hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/Mappings.hbm.xml index 658ef3a4be..8f2d817194 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/Mappings.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/propertyref/cachedcollections/Mappings.hbm.xml @@ -8,7 +8,7 @@ "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> - + diff --git a/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/CachedPropertyRefCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/CachedPropertyRefCollectionTest.java deleted file mode 100644 index 7165b84eb0..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/propertyref/cachedcollections/CachedPropertyRefCollectionTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.test.propertyref.cachedcollections; - -import org.hibernate.Hibernate; -import org.hibernate.Session; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Set of tests originally developed to verify and fix HHH-5853 - * - * @author Steve Ebersole - */ -@TestForIssue( jiraKey = "HHH-5853" ) -public class CachedPropertyRefCollectionTest extends BaseCoreFunctionalTestCase { - @Override - public String[] getMappings() { - return new String[]{"propertyref/cachedcollections/Mappings.hbm.xml"}; - } - - @Test - public void testRetrievalOfCachedCollectionWithPropertyRefKey() { - // create the test data... - Session session = openSession(); - session.beginTransaction(); - ManagedObject mo = new ManagedObject( "test", "test" ); - mo.getMembers().add( "members" ); - session.save( mo ); - session.getTransaction().commit(); - session.close(); - - // First attempt to load it via PK lookup - session = openSession(); - session.beginTransaction(); - ManagedObject obj = session.get( ManagedObject.class, 1L ); - assertNotNull( obj ); - assertTrue( Hibernate.isInitialized( obj ) ); - obj.getMembers().size(); - assertTrue( Hibernate.isInitialized( obj.getMembers() ) ); - session.getTransaction().commit(); - session.close(); - - // Now try to access it via natural key - session = openSession(); - session.beginTransaction(); - obj = session.bySimpleNaturalId( ManagedObject.class ).load( "test" ); - assertNotNull( obj ); - assertTrue( Hibernate.isInitialized( obj ) ); - obj.getMembers().size(); - assertTrue( Hibernate.isInitialized( obj.getMembers() ) ); - session.getTransaction().commit(); - session.close(); - - // Clean up - session = openSession(); - session.beginTransaction(); - session.delete( obj ); - session.getTransaction().commit(); - session.close(); - } -} -