From 4591f78f0f70cb1f3a4b93f404f5b65843434def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 27 Oct 2022 14:47:04 +0200 Subject: [PATCH] Tests for HHH-15634 Lazy basic property does not get updated on change --- .../lazyloading/AbstractLazyBasicTest.java | 206 ++++++++++++++++++ .../LazyBasicDefaultGroupTest.java | 124 +++++++++++ .../LazyBasicMultiNonDefaultGroupTest.java | 127 +++++++++++ .../LazyBasicNonDefaultGroupTest.java | 127 +++++++++++ 4 files changed, 584 insertions(+) create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/AbstractLazyBasicTest.java create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicDefaultGroupTest.java create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicMultiNonDefaultGroupTest.java create mode 100644 extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicNonDefaultGroupTest.java diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/AbstractLazyBasicTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/AbstractLazyBasicTest.java new file mode 100644 index 00000000000000..3c147a00ad77a7 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/AbstractLazyBasicTest.java @@ -0,0 +1,206 @@ +/* + * 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 io.quarkus.hibernate.orm.lazyloading; + +import static io.quarkus.hibernate.orm.TransactionTestUtils.inTransaction; + +import javax.inject.Inject; +import javax.persistence.EntityManager; +import javax.transaction.UserTransaction; + +import org.junit.jupiter.api.Test; + +public abstract class AbstractLazyBasicTest { + + @Inject + EntityManager em; + + @Inject + UserTransaction transaction; + + private final AccessDelegate delegate; + private Long entityId; + + public AbstractLazyBasicTest(AccessDelegate delegate) { + this.delegate = delegate; + } + + @Test + public void update_all_nullToNonNull() { + initNull(); + inTransaction(transaction, () -> { + delegate.updateAllProperties(em, entityId, "updated1", "updated2", "updated3"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "updated1", "updated2", "updated3"); + }); + } + + @Test + public void update_allLazy_nullToNonNull() { + initNull(); + inTransaction(transaction, () -> { + delegate.updateAllLazyProperties(em, entityId, "updated1", "updated2"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, null, "updated1", "updated2"); + }); + } + + @Test + public void update_oneEager_nullToNonNull() { + initNull(); + inTransaction(transaction, () -> { + delegate.updateOneEagerProperty(em, entityId, "updated1"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "updated1", null, null); + }); + } + + @Test + public void update_oneLazy_nullToNonNull() { + initNull(); + inTransaction(transaction, () -> { + delegate.updateOneLazyProperty(em, entityId, "updated2"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, null, "updated2", null); + }); + } + + @Test + public void update_all_nonNullToNonNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateAllProperties(em, entityId, "updated1", "updated2", "updated3"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "updated1", "updated2", "updated3"); + }); + } + + @Test + public void update_allLazy_nonNullToNonNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateAllLazyProperties(em, entityId, "updated1", "updated2"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "initial1", "updated1", "updated2"); + }); + } + + @Test + public void update_oneEager_nonNullToNonNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateOneEagerProperty(em, entityId, "updated1"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "updated1", "initial2", "initial3"); + }); + } + + @Test + public void update_oneLazy_nonNullToNonNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateOneLazyProperty(em, entityId, "updated2"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "initial1", "updated2", "initial3"); + }); + } + + @Test + public void update_all_nonNullToNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateAllProperties(em, entityId, null, null, null); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, null, null, null); + }); + } + + @Test + public void update_allLazy_nonNullToNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateAllLazyProperties(em, entityId, null, null); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "initial1", null, null); + }); + } + + @Test + public void update_oneEager_nonNullToNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateOneEagerProperty(em, entityId, null); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, null, "initial2", "initial3"); + }); + } + + @Test + public void update_oneLazy_nonNullToNull() { + initNonNull(); + inTransaction(transaction, () -> { + delegate.updateOneLazyProperty(em, entityId, null); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "initial1", null, "initial3"); + }); + } + + private void initNull() { + inTransaction(transaction, () -> { + entityId = delegate.create(em, null, null, null); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, null, null, null); + }); + } + + private void initNonNull() { + inTransaction(transaction, () -> { + entityId = delegate.create(em, "initial1", "initial2", "initial3"); + }); + inTransaction(transaction, () -> { + delegate.testLazyLoadingAndPersistedValues(em, entityId, "initial1", "initial2", "initial3"); + }); + } + + /** + * An interface for delegate classes, + * classes whose bytecode is transformed by Quarkus to replace public field access with getter/setter access. + *

+ * (Test bytecode was not transformed by Quarkus when using QuarkusUnitTest last time I checked). + */ + interface AccessDelegate { + + long create(EntityManager entityManager, String eagerProperty1, String lazyProperty1, String lazyProperty2); + + void updateAllProperties(EntityManager entityManager, long entityId, String eagerProperty1, String lazyProperty1, + String lazyProperty2); + + void updateAllLazyProperties(EntityManager entityManager, long entityId, String lazyProperty1, String lazyProperty2); + + void updateOneEagerProperty(EntityManager entityManager, long entityId, String eagerProperty1); + + void updateOneLazyProperty(EntityManager entityManager, long entityId, String lazyProperty1); + + void testLazyLoadingAndPersistedValues(EntityManager entityManager, long entityId, + String expectedEagerProperty1, + String expectedLazyProperty1, + String expectedLazyProperty2); + } +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicDefaultGroupTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicDefaultGroupTest.java new file mode 100644 index 00000000000000..ba57457d0634a6 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicDefaultGroupTest.java @@ -0,0 +1,124 @@ +/* + * 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 io.quarkus.hibernate.orm.lazyloading; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.Hibernate; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.TransactionTestUtils; +import io.quarkus.test.QuarkusUnitTest; + +public class LazyBasicDefaultGroupTest extends AbstractLazyBasicTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(TransactionTestUtils.class) + .addClass(MyEntity.class) + .addClass(AccessDelegate.class) + .addClass(AccessDelegateImpl.class)) + .withConfigurationResource("application.properties"); + + public LazyBasicDefaultGroupTest() { + super(new AccessDelegateImpl()); + } + + @Entity(name = "MyEntity") + public static class MyEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long id; + + @Basic + public String eagerProperty1; + + @Basic(fetch = FetchType.LAZY) + public String lazyProperty1; + + @Basic(fetch = FetchType.LAZY) + public String lazyProperty2; + } + + private static class AccessDelegateImpl implements AccessDelegate { + + @Override + public long create(EntityManager entityManager, String eagerProperty1, String lazyProperty1, String lazyProperty2) { + MyEntity myEntity = new MyEntity(); + myEntity.eagerProperty1 = eagerProperty1; + myEntity.lazyProperty1 = lazyProperty1; + myEntity.lazyProperty2 = lazyProperty2; + entityManager.persist(myEntity); + return myEntity.id; + } + + @Override + public void updateAllProperties(EntityManager entityManager, long entityId, String eagerProperty1, String lazyProperty1, + String lazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.eagerProperty1 = eagerProperty1; + entity.lazyProperty1 = lazyProperty1; + entity.lazyProperty2 = lazyProperty2; + } + + @Override + public void updateAllLazyProperties(EntityManager entityManager, long entityId, String lazyProperty1, + String lazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.lazyProperty1 = lazyProperty1; + entity.lazyProperty2 = lazyProperty2; + } + + @Override + public void updateOneEagerProperty(EntityManager entityManager, long entityId, String eagerProperty1) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.eagerProperty1 = eagerProperty1; + } + + @Override + public void updateOneLazyProperty(EntityManager entityManager, long entityId, String lazyProperty1) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.lazyProperty1 = lazyProperty1; + } + + @Override + public void testLazyLoadingAndPersistedValues(EntityManager entityManager, long entityId, + String expectedEagerProperty1, + String expectedLazyProperty1, + String expectedLazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + assertThat(entity).isNotNull(); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isFalse(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.eagerProperty1).isEqualTo(expectedEagerProperty1); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isFalse(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.lazyProperty1).isEqualTo(expectedLazyProperty1); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isTrue(); + + assertThat(entity.lazyProperty2).isEqualTo(expectedLazyProperty2); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isTrue(); + } + } +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicMultiNonDefaultGroupTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicMultiNonDefaultGroupTest.java new file mode 100644 index 00000000000000..6bbe46daa76fe5 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicMultiNonDefaultGroupTest.java @@ -0,0 +1,127 @@ +/* + * 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 io.quarkus.hibernate.orm.lazyloading; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.Hibernate; +import org.hibernate.annotations.LazyGroup; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.TransactionTestUtils; +import io.quarkus.test.QuarkusUnitTest; + +public class LazyBasicMultiNonDefaultGroupTest extends AbstractLazyBasicTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(TransactionTestUtils.class) + .addClass(MyEntity.class) + .addClass(AccessDelegate.class) + .addClass(AccessDelegateImpl.class)) + .withConfigurationResource("application.properties"); + + public LazyBasicMultiNonDefaultGroupTest() { + super(new AccessDelegateImpl()); + } + + @Entity(name = "MyEntity") + public static class MyEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long id; + + @Basic + public String eagerProperty1; + + @Basic(fetch = FetchType.LAZY) + @LazyGroup("myGroup1") + public String lazyProperty1; + + @Basic(fetch = FetchType.LAZY) + @LazyGroup("myGroup2") + public String lazyProperty2; + } + + private static class AccessDelegateImpl implements AccessDelegate { + + @Override + public long create(EntityManager entityManager, String eagerProperty1, String lazyProperty1, String lazyProperty2) { + MyEntity myEntity = new MyEntity(); + myEntity.eagerProperty1 = eagerProperty1; + myEntity.lazyProperty1 = lazyProperty1; + myEntity.lazyProperty2 = lazyProperty2; + entityManager.persist(myEntity); + return myEntity.id; + } + + @Override + public void updateAllProperties(EntityManager entityManager, long entityId, String eagerProperty1, String lazyProperty1, + String lazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.eagerProperty1 = eagerProperty1; + entity.lazyProperty1 = lazyProperty1; + entity.lazyProperty2 = lazyProperty2; + } + + @Override + public void updateAllLazyProperties(EntityManager entityManager, long entityId, String lazyProperty1, + String lazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.lazyProperty1 = lazyProperty1; + entity.lazyProperty2 = lazyProperty2; + } + + @Override + public void updateOneEagerProperty(EntityManager entityManager, long entityId, String eagerProperty1) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.eagerProperty1 = eagerProperty1; + } + + @Override + public void updateOneLazyProperty(EntityManager entityManager, long entityId, String lazyProperty1) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.lazyProperty1 = lazyProperty1; + } + + @Override + public void testLazyLoadingAndPersistedValues(EntityManager entityManager, long entityId, + String expectedEagerProperty1, + String expectedLazyProperty1, + String expectedLazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + assertThat(entity).isNotNull(); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isFalse(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.eagerProperty1).isEqualTo(expectedEagerProperty1); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isFalse(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.lazyProperty1).isEqualTo(expectedLazyProperty1); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.lazyProperty2).isEqualTo(expectedLazyProperty2); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isTrue(); + } + } +} diff --git a/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicNonDefaultGroupTest.java b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicNonDefaultGroupTest.java new file mode 100644 index 00000000000000..b43ab99392db77 --- /dev/null +++ b/extensions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/lazyloading/LazyBasicNonDefaultGroupTest.java @@ -0,0 +1,127 @@ +/* + * 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 io.quarkus.hibernate.orm.lazyloading; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.persistence.Basic; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import org.hibernate.Hibernate; +import org.hibernate.annotations.LazyGroup; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.hibernate.orm.TransactionTestUtils; +import io.quarkus.test.QuarkusUnitTest; + +public class LazyBasicNonDefaultGroupTest extends AbstractLazyBasicTest { + + @RegisterExtension + static QuarkusUnitTest runner = new QuarkusUnitTest() + .withApplicationRoot((jar) -> jar + .addClass(TransactionTestUtils.class) + .addClass(MyEntity.class) + .addClass(AccessDelegate.class) + .addClass(AccessDelegateImpl.class)) + .withConfigurationResource("application.properties"); + + public LazyBasicNonDefaultGroupTest() { + super(new AccessDelegateImpl()); + } + + @Entity(name = "MyEntity") + public static class MyEntity { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + public Long id; + + @Basic + public String eagerProperty1; + + @Basic(fetch = FetchType.LAZY) + @LazyGroup("myGroup") + public String lazyProperty1; + + @Basic(fetch = FetchType.LAZY) + @LazyGroup("myGroup") + public String lazyProperty2; + } + + private static class AccessDelegateImpl implements AccessDelegate { + + @Override + public long create(EntityManager entityManager, String eagerProperty1, String lazyProperty1, String lazyProperty2) { + MyEntity myEntity = new MyEntity(); + myEntity.eagerProperty1 = eagerProperty1; + myEntity.lazyProperty1 = lazyProperty1; + myEntity.lazyProperty2 = lazyProperty2; + entityManager.persist(myEntity); + return myEntity.id; + } + + @Override + public void updateAllProperties(EntityManager entityManager, long entityId, String eagerProperty1, String lazyProperty1, + String lazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.eagerProperty1 = eagerProperty1; + entity.lazyProperty1 = lazyProperty1; + entity.lazyProperty2 = lazyProperty2; + } + + @Override + public void updateAllLazyProperties(EntityManager entityManager, long entityId, String lazyProperty1, + String lazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.lazyProperty1 = lazyProperty1; + entity.lazyProperty2 = lazyProperty2; + } + + @Override + public void updateOneEagerProperty(EntityManager entityManager, long entityId, String eagerProperty1) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.eagerProperty1 = eagerProperty1; + } + + @Override + public void updateOneLazyProperty(EntityManager entityManager, long entityId, String lazyProperty1) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + entity.lazyProperty1 = lazyProperty1; + } + + @Override + public void testLazyLoadingAndPersistedValues(EntityManager entityManager, long entityId, + String expectedEagerProperty1, + String expectedLazyProperty1, + String expectedLazyProperty2) { + MyEntity entity = entityManager.find(MyEntity.class, entityId); + assertThat(entity).isNotNull(); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isFalse(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.eagerProperty1).isEqualTo(expectedEagerProperty1); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isFalse(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isFalse(); + + assertThat(entity.lazyProperty1).isEqualTo(expectedLazyProperty1); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isTrue(); + + assertThat(entity.lazyProperty2).isEqualTo(expectedLazyProperty2); + assertThat(Hibernate.isPropertyInitialized(entity, "eagerProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty1")).isTrue(); + assertThat(Hibernate.isPropertyInitialized(entity, "lazyProperty2")).isTrue(); + } + } +}