@@ -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
71110void tearDown (SessionFactoryScope scope ) {
72111scope .getSessionFactory ().getSchemaManager ().truncateMappedObjects ();
0 commit comments