Skip to content

Commit 61707e3

Browse files
committed
HHH-19856 @LazyGroup is not always respected
1 parent 2c4584a commit 61707e3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/lazytoone/LazyOneToOneWithCastTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,45 @@ void oneNullOneNotNull(SessionFactoryScope scope) {
6767
} );
6868
}
6969

70+
@Test
71+
void bothNotNull(SessionFactoryScope scope) {
72+
scope.inTransaction( session -> {
73+
ContainingEntity containingEntity1 = new ContainingEntity();
74+
containingEntity1.setId( 1 );
75+
76+
ContainedEntity contained1 = new ContainedEntity();
77+
contained1.setId( 4 );
78+
contained1.setContainingAsIndexedEmbeddedWithCast( containingEntity1 );
79+
containingEntity1.setContainedIndexedEmbeddedWithCast( contained1 );
80+
81+
contained1.setContainingAsIndexedEmbedded( containingEntity1 );
82+
containingEntity1.setContainedIndexedEmbedded( contained1 );
83+
84+
85+
session.persist( contained1 );
86+
session.persist( containingEntity1 );
87+
88+
} );
89+
90+
scope.inTransaction( session -> {
91+
ContainedEntity contained = session.find( ContainedEntity.class, 4 );
92+
93+
ContainingEntity containingAsIndexedEmbedded = contained.getContainingAsIndexedEmbedded();
94+
assertThat( containingAsIndexedEmbedded ).isNotNull();
95+
assertThat( Hibernate.isPropertyInitialized( contained, "containingAsIndexedEmbedded" ) ).isTrue();
96+
assertThat( Hibernate.isPropertyInitialized( contained, "containingAsIndexedEmbeddedWithCast" ) ).isFalse();
97+
98+
Object containingAsIndexedEmbeddedWithCast = contained.getContainingAsIndexedEmbeddedWithCast();
99+
assertThat( Hibernate.isPropertyInitialized( contained, "containingAsIndexedEmbeddedWithCast" ) ).isTrue();
100+
assertThat( containingAsIndexedEmbeddedWithCast ).isNotNull();
101+
} );
102+
103+
scope.inTransaction( session -> {
104+
ContainedEntity contained = session.find( ContainedEntity.class, 4 );
105+
assertThat( contained.getContainingAsIndexedEmbeddedWithCast() ).isNotNull();
106+
} );
107+
}
108+
70109
@AfterEach
71110
void tearDown(SessionFactoryScope scope) {
72111
scope.getSessionFactory().getSchemaManager().truncateMappedObjects();

0 commit comments

Comments
 (0)