HHH-15634 Test updating a single lazy property with no lazy group

This commit is contained in:
Yoann Rodière 2022-10-26 13:23:32 +02:00 committed by Christian Beikov
parent 66daac53a2
commit b82d906841
2 changed files with 66 additions and 6 deletions

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy.basic;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert; import org.junit.Assert;
@ -63,7 +64,37 @@ public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void execute() { public void testAttachedUpdate() {
doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId );
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
checkDirtyTracking( entity );
assertEquals( "desc", entity.description );
assertTrue( isPropertyInitialized( entity, "description" ) );
} );
doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId );
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
entity.description = "desc1";
checkDirtyTracking( entity, "description" );
assertEquals( "desc1", entity.description );
assertTrue( isPropertyInitialized( entity, "description" ) );
} );
doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId );
assertEquals( "desc1", entity.description );
} );
}
@Test
@TestForIssue(jiraKey = "HHH-11882")
public void testDetachedUpdate() {
doInHibernate( this::sessionFactory, s -> { doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId ); entity = s.get( LazyEntity.class, entityId );
@ -78,7 +109,6 @@ public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase {
entity.description = "desc1"; entity.description = "desc1";
s.update( entity ); s.update( entity );
// Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
checkDirtyTracking( entity, "description" ); checkDirtyTracking( entity, "description" );
assertEquals( "desc1", entity.description ); assertEquals( "desc1", entity.description );
@ -102,7 +132,7 @@ public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase {
} ); } );
doInHibernate( this::sessionFactory, s -> { doInHibernate( this::sessionFactory, s -> {
LazyEntity entity = s.get( LazyEntity.class, entityId ); entity = s.get( LazyEntity.class, entityId );
assertEquals( "desc2", entity.description ); assertEquals( "desc2", entity.description );
} ); } );
} }

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.bytecode.enhancement.lazy.basic;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner; import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert; import org.junit.Assert;
@ -60,7 +61,37 @@ public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
public void test() { public void testAttachedUpdate() {
doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId );
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
checkDirtyTracking( entity );
assertEquals( "desc", entity.getDescription() );
assertTrue( isPropertyInitialized( entity, "description" ) );
} );
doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId );
Assert.assertFalse( isPropertyInitialized( entity, "description" ) );
entity.setDescription( "desc1" );
checkDirtyTracking( entity, "description" );
assertEquals( "desc1", entity.getDescription() );
assertTrue( isPropertyInitialized( entity, "description" ) );
} );
doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId );
assertEquals( "desc1", entity.getDescription() );
} );
}
@Test
@TestForIssue(jiraKey = "HHH-11882")
public void testDetachedUpdate() {
doInHibernate( this::sessionFactory, s -> { doInHibernate( this::sessionFactory, s -> {
entity = s.get( LazyEntity.class, entityId ); entity = s.get( LazyEntity.class, entityId );
@ -75,7 +106,6 @@ public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase {
entity.setDescription( "desc1" ); entity.setDescription( "desc1" );
s.update( entity ); s.update( entity );
//Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
checkDirtyTracking( entity, "description" ); checkDirtyTracking( entity, "description" );
assertEquals( "desc1", entity.getDescription() ); assertEquals( "desc1", entity.getDescription() );
@ -99,7 +129,7 @@ public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase {
} ); } );
doInHibernate( this::sessionFactory, s -> { doInHibernate( this::sessionFactory, s -> {
LazyEntity entity = s.get( LazyEntity.class, entityId ); entity = s.get( LazyEntity.class, entityId );
assertEquals( "desc2", entity.getDescription() ); assertEquals( "desc2", entity.getDescription() );
} ); } );
} }