Skip to content

Commit

Permalink
HHH-15634 Test updating a single lazy property with no lazy group
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere authored and beikov committed Oct 31, 2022
1 parent 66daac5 commit b82d906
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
Expand Down Expand Up @@ -63,7 +64,37 @@ public void prepare() {
}

@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 -> {
entity = s.get( LazyEntity.class, entityId );

Expand All @@ -78,7 +109,6 @@ public void execute() {
entity.description = "desc1";
s.update( entity );

// Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
checkDirtyTracking( entity, "description" );

assertEquals( "desc1", entity.description );
Expand All @@ -102,7 +132,7 @@ public void execute() {
} );

doInHibernate( this::sessionFactory, s -> {
LazyEntity entity = s.get( LazyEntity.class, entityId );
entity = s.get( LazyEntity.class, entityId );
assertEquals( "desc2", entity.description );
} );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;

import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
Expand Down Expand Up @@ -60,7 +61,37 @@ public void prepare() {
}

@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 -> {
entity = s.get( LazyEntity.class, entityId );

Expand All @@ -75,7 +106,6 @@ public void test() {
entity.setDescription( "desc1" );
s.update( entity );

//Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) );
checkDirtyTracking( entity, "description" );

assertEquals( "desc1", entity.getDescription() );
Expand All @@ -99,7 +129,7 @@ public void test() {
} );

doInHibernate( this::sessionFactory, s -> {
LazyEntity entity = s.get( LazyEntity.class, entityId );
entity = s.get( LazyEntity.class, entityId );
assertEquals( "desc2", entity.getDescription() );
} );
}
Expand Down

0 comments on commit b82d906

Please sign in to comment.