Skip to content

Commit a2bac94

Browse files
geoandDavideD
authored andcommitted
Work around lazy eager loading issue in clean DB for NonNullableManyToOneTest
Furthermore, use property access instead of field access
1 parent a9ab99d commit a2bac94

File tree

1 file changed

+92
-4
lines changed

1 file changed

+92
-4
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/NonNullableManyToOneTest.java

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import jakarta.persistence.Table;
1717

1818

19+
import org.junit.After;
1920
import org.junit.Before;
2021
import org.junit.Test;
2122

@@ -43,25 +44,33 @@ public void populateDB(TestContext context) {
4344
.withTransaction( s -> s.persistAll( painting, artist, dealer ) ) );
4445
}
4546

47+
@After
48+
public void cleanDb(TestContext context) {
49+
test( context, getSessionFactory()
50+
.withTransaction( s -> s.createQuery( "delete from Painting" ).executeUpdate()
51+
.thenCompose( v -> s.createQuery( "delete from Artist" ).executeUpdate() )
52+
.thenCompose( v -> s.createQuery( "delete from Dealer" ).executeUpdate())) );
53+
}
54+
4655
@Test
4756
public void testNonNullableSuccess(TestContext context) {
4857
test( context, getMutinySessionFactory()
4958
.withTransaction( session -> session
5059
.createQuery( "from Artist", Artist.class )
51-
.getSingleResult().chain( a -> session.fetch( a.paintings ) )
60+
.getSingleResult().chain( a -> session.fetch( a.getPaintings() ) )
5261
.invoke( paintings -> {
5362
context.assertNotNull( paintings );
5463
context.assertEquals( 1, paintings.size() );
55-
context.assertEquals( "Mona Lisa", paintings.get( 0 ).name );
64+
context.assertEquals( "Mona Lisa", paintings.get( 0 ).getName() );
5665
} ) )
5766
.chain( () -> getMutinySessionFactory()
5867
.withTransaction( s1 -> s1
5968
.createQuery( "from Dealer", Dealer.class )
60-
.getSingleResult().chain( d -> s1.fetch( d.paintings ) )
69+
.getSingleResult().chain( d -> s1.fetch( d.getPaintings() ) )
6170
.invoke( paintings -> {
6271
context.assertNotNull( paintings );
6372
context.assertEquals( 1, paintings.size() );
64-
context.assertEquals( "Mona Lisa", paintings.get( 0 ).name );
73+
context.assertEquals( "Mona Lisa", paintings.get( 0 ).getName() );
6574
} )
6675
)
6776
)
@@ -89,6 +98,39 @@ public Painting() {
8998
public Painting(String name) {
9099
this.name = name;
91100
}
101+
102+
103+
public Long getId() {
104+
return id;
105+
}
106+
107+
public void setId(Long id) {
108+
this.id = id;
109+
}
110+
111+
public String getName() {
112+
return name;
113+
}
114+
115+
public void setName(String name) {
116+
this.name = name;
117+
}
118+
119+
public Artist getAuthor() {
120+
return author;
121+
}
122+
123+
public void setAuthor(Artist author) {
124+
this.author = author;
125+
}
126+
127+
public Dealer getDealer() {
128+
return dealer;
129+
}
130+
131+
public void setDealer(Dealer dealer) {
132+
this.dealer = dealer;
133+
}
92134
}
93135

94136
@Entity(name = "Artist")
@@ -114,6 +156,29 @@ public void addPainting(Painting painting) {
114156
painting.author = this;
115157
}
116158

159+
public Long getId() {
160+
return id;
161+
}
162+
163+
public void setId(Long id) {
164+
this.id = id;
165+
}
166+
167+
public String getName() {
168+
return name;
169+
}
170+
171+
public void setName(String name) {
172+
this.name = name;
173+
}
174+
175+
public List<Painting> getPaintings() {
176+
return paintings;
177+
}
178+
179+
public void setPaintings(List<Painting> paintings) {
180+
this.paintings = paintings;
181+
}
117182
}
118183

119184
@Entity(name = "Dealer")
@@ -139,5 +204,28 @@ public void addPainting(Painting painting) {
139204
painting.dealer = this;
140205
}
141206

207+
public Long getId() {
208+
return id;
209+
}
210+
211+
public void setId(Long id) {
212+
this.id = id;
213+
}
214+
215+
public String getName() {
216+
return name;
217+
}
218+
219+
public void setName(String name) {
220+
this.name = name;
221+
}
222+
223+
public List<Painting> getPaintings() {
224+
return paintings;
225+
}
226+
227+
public void setPaintings(List<Painting> paintings) {
228+
this.paintings = paintings;
229+
}
142230
}
143231
}

0 commit comments

Comments
 (0)