From 9054f11b0183d91537ce67f12c5b7ae582abe67d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Wed, 26 Oct 2022 13:07:06 +0200 Subject: [PATCH] HHH-15634 Fix naming of LazyBasicFieldAccessTest/LazyBasicPropertyAccessTest For some reason they were reversed. --- .../lazy/basic/LazyBasicFieldAccessTest.java | 46 +++++++----------- .../basic/LazyBasicPropertyAccessTest.java | 48 +++++++++++-------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java index 4d07652d8c..adcde3b4db 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicFieldAccessTest.java @@ -16,6 +16,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import javax.persistence.Access; +import javax.persistence.AccessType; import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -36,6 +38,7 @@ import static org.junit.Assert.assertTrue; public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase { private LazyEntity entity; + private Long entityId; @Override @@ -53,82 +56,69 @@ public class LazyBasicFieldAccessTest extends BaseCoreFunctionalTestCase { public void prepare() { doInHibernate( this::sessionFactory, s -> { LazyEntity entity = new LazyEntity(); - entity.setDescription( "desc" ); + entity.description = "desc"; s.persist( entity ); entityId = entity.id; } ); } @Test - public void test() { + public void execute() { doInHibernate( this::sessionFactory, s -> { entity = s.get( LazyEntity.class, entityId ); Assert.assertFalse( isPropertyInitialized( entity, "description" ) ); checkDirtyTracking( entity ); - assertEquals( "desc", entity.getDescription() ); + assertEquals( "desc", entity.description ); assertTrue( isPropertyInitialized( entity, "description" ) ); } ); doInHibernate( this::sessionFactory, s -> { - entity.setDescription( "desc1" ); + entity.description = "desc1"; s.update( entity ); - //Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); + // Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); checkDirtyTracking( entity, "description" ); - assertEquals( "desc1", entity.getDescription() ); + assertEquals( "desc1", entity.description ); assertTrue( isPropertyInitialized( entity, "description" ) ); } ); doInHibernate( this::sessionFactory, s -> { entity = s.get( LazyEntity.class, entityId ); - assertEquals( "desc1", entity.getDescription() ); + assertEquals( "desc1", entity.description ); } ); doInHibernate( this::sessionFactory, s -> { - entity.setDescription( "desc2" ); + entity.description = "desc2"; LazyEntity mergedEntity = (LazyEntity) s.merge( entity ); - // Assert.assertFalse( isPropertyInitialized( entity, "description" ) ); + //Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); checkDirtyTracking( mergedEntity, "description" ); - assertEquals( "desc2", mergedEntity.getDescription() ); + assertEquals( "desc2", mergedEntity.description ); assertTrue( isPropertyInitialized( mergedEntity, "description" ) ); } ); doInHibernate( this::sessionFactory, s -> { LazyEntity entity = s.get( LazyEntity.class, entityId ); - assertEquals( "desc2", entity.getDescription() ); + assertEquals( "desc2", entity.description ); } ); } // --- // @Entity - @Table( name = "LAZY_FIELD_ENTITY" ) + @Access( AccessType.FIELD ) + @Table( name = "LAZY_PROPERTY_ENTITY" ) private static class LazyEntity { - Long id; - String description; @Id @GeneratedValue - Long getId() { - return id; - } - - void setId(Long id) { - this.id = id; - } + Long id; @Basic( fetch = FetchType.LAZY ) - String getDescription() { - return description; - } - - void setDescription(String description) { - this.description = description; - } + String description; } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java index a41949fca9..aa344779f1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/basic/LazyBasicPropertyAccessTest.java @@ -16,8 +16,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import javax.persistence.Access; -import javax.persistence.AccessType; import javax.persistence.Basic; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -38,7 +36,6 @@ import static org.junit.Assert.assertTrue; public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase { private LazyEntity entity; - private Long entityId; @Override @@ -56,69 +53,82 @@ public class LazyBasicPropertyAccessTest extends BaseCoreFunctionalTestCase { public void prepare() { doInHibernate( this::sessionFactory, s -> { LazyEntity entity = new LazyEntity(); - entity.description = "desc"; + entity.setDescription( "desc" ); s.persist( entity ); - entityId = entity.id; + entityId = entity.getId(); } ); } @Test - public void execute() { + public void test() { doInHibernate( this::sessionFactory, s -> { entity = s.get( LazyEntity.class, entityId ); Assert.assertFalse( isPropertyInitialized( entity, "description" ) ); checkDirtyTracking( entity ); - assertEquals( "desc", entity.description ); + assertEquals( "desc", entity.getDescription() ); assertTrue( isPropertyInitialized( entity, "description" ) ); } ); doInHibernate( this::sessionFactory, s -> { - entity.description = "desc1"; + entity.setDescription( "desc1" ); s.update( entity ); - // Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); + //Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); checkDirtyTracking( entity, "description" ); - assertEquals( "desc1", entity.description ); + assertEquals( "desc1", entity.getDescription() ); assertTrue( isPropertyInitialized( entity, "description" ) ); } ); doInHibernate( this::sessionFactory, s -> { entity = s.get( LazyEntity.class, entityId ); - assertEquals( "desc1", entity.description ); + assertEquals( "desc1", entity.getDescription() ); } ); doInHibernate( this::sessionFactory, s -> { - entity.description = "desc2"; + entity.setDescription( "desc2" ); LazyEntity mergedEntity = (LazyEntity) s.merge( entity ); - //Assert.assertFalse( Hibernate.isPropertyInitialized( entity, "description" ) ); + // Assert.assertFalse( isPropertyInitialized( entity, "description" ) ); checkDirtyTracking( mergedEntity, "description" ); - assertEquals( "desc2", mergedEntity.description ); + assertEquals( "desc2", mergedEntity.getDescription() ); assertTrue( isPropertyInitialized( mergedEntity, "description" ) ); } ); doInHibernate( this::sessionFactory, s -> { LazyEntity entity = s.get( LazyEntity.class, entityId ); - assertEquals( "desc2", entity.description ); + assertEquals( "desc2", entity.getDescription() ); } ); } // --- // @Entity - @Access( AccessType.FIELD ) - @Table( name = "LAZY_PROPERTY_ENTITY" ) + @Table( name = "LAZY_FIELD_ENTITY" ) private static class LazyEntity { + Long id; + String description; @Id @GeneratedValue - Long id; + Long getId() { + return id; + } + + void setId(Long id) { + this.id = id; + } @Basic( fetch = FetchType.LAZY ) - String description; + String getDescription() { + return description; + } + + void setDescription(String description) { + this.description = description; + } } }