-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-15522 Add hibernate isInitialized tests on envers collections
- Loading branch information
Showing
2 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...nate/orm/test/envers/integration/lazy/IsCollectionInitializedBytecodeEnhancementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.orm.test.envers.integration.lazy; | ||
|
||
import java.util.List; | ||
import jakarta.persistence.EntityManager; | ||
|
||
import org.hibernate.dialect.OracleDialect; | ||
import org.hibernate.envers.query.AuditEntity; | ||
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase; | ||
import org.hibernate.orm.test.envers.Priority; | ||
import org.hibernate.orm.test.envers.entities.collection.MultipleCollectionEntity; | ||
import org.hibernate.orm.test.envers.entities.collection.MultipleCollectionRefEntity1; | ||
import org.hibernate.orm.test.envers.entities.collection.MultipleCollectionRefEntity2; | ||
import org.hibernate.testing.SkipForDialect; | ||
import org.hibernate.testing.TestForIssue; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import static org.junit.Assert.assertEquals; | ||
import org.hibernate.Hibernate; | ||
import org.hibernate.envers.AuditReader; | ||
import org.hibernate.envers.AuditReaderFactory; | ||
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; | ||
import org.hibernate.testing.bytecode.enhancement.EnhancementOptions; | ||
|
||
/** | ||
* @author Fabricio Gregorio | ||
*/ | ||
@TestForIssue(jiraKey = "HHH-15522") | ||
@RunWith(BytecodeEnhancerRunner.class) | ||
@EnhancementOptions(lazyLoading = true) | ||
@SkipForDialect(value = OracleDialect.class, comment = "Oracle does not support identity key generation") | ||
public class IsCollectionInitializedBytecodeEnhancementTest extends BaseEnversJPAFunctionalTestCase { | ||
|
||
private Long mce1Id = null; | ||
private Long mcre1Id = null; | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[]{ | ||
MultipleCollectionEntity.class, MultipleCollectionRefEntity1.class, MultipleCollectionRefEntity2.class | ||
}; | ||
} | ||
|
||
@Test | ||
@Priority(10) | ||
public void initData() { | ||
EntityManager em = getEntityManager(); | ||
|
||
// Revision 1 - addition. | ||
em.getTransaction().begin(); | ||
MultipleCollectionEntity mce1 = new MultipleCollectionEntity(); | ||
mce1.setText( "MultipleCollectionEntity-1-1" ); | ||
em.persist( mce1 ); // Persisting entity with empty collections. | ||
em.getTransaction().commit(); | ||
|
||
mce1Id = mce1.getId(); | ||
|
||
// Revision 2 - update. | ||
em.getTransaction().begin(); | ||
mce1 = em.find( MultipleCollectionEntity.class, mce1.getId() ); | ||
MultipleCollectionRefEntity1 mcre1 = new MultipleCollectionRefEntity1(); | ||
mcre1.setText( "MultipleCollectionRefEntity1-1-1" ); | ||
mcre1.setMultipleCollectionEntity( mce1 ); | ||
mce1.addRefEntity1( mcre1 ); | ||
em.persist( mcre1 ); | ||
mce1 = em.merge( mce1 ); | ||
em.getTransaction().commit(); | ||
|
||
mcre1Id = mcre1.getId(); | ||
|
||
em.close(); | ||
} | ||
|
||
@Test | ||
public void testIsInitialized() { | ||
EntityManager em = getEntityManager(); | ||
|
||
AuditReader reader = AuditReaderFactory.get( em ); | ||
List<MultipleCollectionEntity> res = reader.createQuery().forEntitiesAtRevision( MultipleCollectionEntity.class, 1 ) | ||
.add( AuditEntity.id().eq( mce1Id ) ) | ||
.getResultList(); | ||
|
||
MultipleCollectionEntity ret = res.get( 0 ); | ||
|
||
assertEquals( Hibernate.isInitialized( ret.getRefEntities1() ), false ); | ||
|
||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...test/java/org/hibernate/orm/test/envers/integration/lazy/IsCollectionInitializedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.orm.test.envers.integration.lazy; | ||
|
||
import java.util.List; | ||
import jakarta.persistence.EntityManager; | ||
|
||
import org.hibernate.dialect.OracleDialect; | ||
import org.hibernate.envers.query.AuditEntity; | ||
import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase; | ||
import org.hibernate.orm.test.envers.Priority; | ||
import org.hibernate.orm.test.envers.entities.collection.MultipleCollectionEntity; | ||
import org.hibernate.orm.test.envers.entities.collection.MultipleCollectionRefEntity1; | ||
import org.hibernate.orm.test.envers.entities.collection.MultipleCollectionRefEntity2; | ||
import org.hibernate.testing.SkipForDialect; | ||
import org.hibernate.testing.TestForIssue; | ||
import org.junit.Test; | ||
import static org.junit.Assert.assertEquals; | ||
import org.hibernate.Hibernate; | ||
import org.hibernate.envers.AuditReader; | ||
import org.hibernate.envers.AuditReaderFactory; | ||
|
||
/** | ||
* @author Fabricio Gregorio | ||
*/ | ||
@TestForIssue(jiraKey = "HHH-15522") | ||
@SkipForDialect(value = OracleDialect.class, comment = "Oracle does not support identity key generation") | ||
public class IsCollectionInitializedTest extends BaseEnversJPAFunctionalTestCase { | ||
|
||
private Long mce1Id = null; | ||
private Long mcre1Id = null; | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[]{ | ||
MultipleCollectionEntity.class, MultipleCollectionRefEntity1.class, MultipleCollectionRefEntity2.class | ||
}; | ||
} | ||
|
||
@Test | ||
@Priority(10) | ||
public void initData() { | ||
EntityManager em = getEntityManager(); | ||
|
||
// Revision 1 - addition. | ||
em.getTransaction().begin(); | ||
MultipleCollectionEntity mce1 = new MultipleCollectionEntity(); | ||
mce1.setText( "MultipleCollectionEntity-1-1" ); | ||
em.persist( mce1 ); // Persisting entity with empty collections. | ||
em.getTransaction().commit(); | ||
|
||
mce1Id = mce1.getId(); | ||
|
||
// Revision 2 - update. | ||
em.getTransaction().begin(); | ||
mce1 = em.find( MultipleCollectionEntity.class, mce1.getId() ); | ||
MultipleCollectionRefEntity1 mcre1 = new MultipleCollectionRefEntity1(); | ||
mcre1.setText( "MultipleCollectionRefEntity1-1-1" ); | ||
mcre1.setMultipleCollectionEntity( mce1 ); | ||
mce1.addRefEntity1( mcre1 ); | ||
em.persist( mcre1 ); | ||
mce1 = em.merge( mce1 ); | ||
em.getTransaction().commit(); | ||
|
||
mcre1Id = mcre1.getId(); | ||
|
||
em.close(); | ||
} | ||
|
||
@Test | ||
public void testIsInitialized() { | ||
EntityManager em = getEntityManager(); | ||
|
||
AuditReader reader = AuditReaderFactory.get( em ); | ||
List<MultipleCollectionEntity> res = reader.createQuery().forEntitiesAtRevision( MultipleCollectionEntity.class, 1 ) | ||
.add( AuditEntity.id().eq( mce1Id ) ) | ||
.getResultList(); | ||
|
||
MultipleCollectionEntity ret = res.get( 0 ); | ||
|
||
assertEquals( Hibernate.isInitialized( ret.getRefEntities1() ), false ); | ||
|
||
} | ||
} |