Skip to content

Commit bf917b9

Browse files
geoandDavideD
authored andcommitted
Fix SubselectFetchTest
As mentioned in https://hibernate.atlassian.net/browse/HHH-16136, property access worked by chance in ORM 5, but no longer does in 6, so we update the test to use gette access
1 parent f08db22 commit bf917b9

File tree

1 file changed

+111
-9
lines changed

1 file changed

+111
-9
lines changed

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

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hibernate.annotations.Fetch;
1515
import org.hibernate.annotations.FetchMode;
1616

17+
import org.junit.After;
1718
import org.junit.Test;
1819

1920
import io.vertx.ext.unit.TestContext;
@@ -42,6 +43,13 @@ protected Collection<Class<?>> annotatedEntities() {
4243
return List.of( Element.class, Node.class );
4344
}
4445

46+
@After
47+
public void cleanDb(TestContext context) {
48+
test( context, getSessionFactory()
49+
.withTransaction( s -> s.createQuery( "delete from Element" ).executeUpdate()
50+
.thenCompose( v -> s.createQuery( "delete from Node" ).executeUpdate() ) ) );
51+
}
52+
4553
@Test
4654
public void testQuery(TestContext context) {
4755
Node basik = new Node( "Child" );
@@ -52,23 +60,21 @@ public void testQuery(TestContext context) {
5260
basik.parent.elements.add( new Element( basik.parent ) );
5361
basik.parent.elements.add( new Element( basik.parent ) );
5462

55-
test(
56-
context,
57-
openSession()
58-
.thenCompose( s -> s.persist( basik ).thenCompose( v -> s.flush() ) )
63+
test( context, getSessionFactory()
64+
.withTransaction( s -> s.persist( basik ) )
5965
.thenCompose( v -> openSession() )
6066
.thenCompose( s -> s.createQuery( "from Node n order by id", Node.class )
6167
.getResultList()
6268
.thenCompose( list -> {
6369
context.assertEquals( list.size(), 2 );
6470
Node n1 = list.get( 0 );
6571
Node n2 = list.get( 1 );
66-
context.assertFalse( Hibernate.isInitialized( n1.elements ) );
67-
context.assertFalse( Hibernate.isInitialized( n2.elements ) );
68-
return s.fetch( n1.elements ).thenAccept( elements -> {
72+
context.assertFalse( Hibernate.isInitialized( n1.getElements() ) );
73+
context.assertFalse( Hibernate.isInitialized( n2.getElements() ) );
74+
return s.fetch( n1.getElements() ).thenAccept( elements -> {
6975
context.assertTrue( Hibernate.isInitialized( elements ) );
70-
context.assertTrue( Hibernate.isInitialized( n1.elements ) );
71-
context.assertTrue( Hibernate.isInitialized( n2.elements ) );
76+
context.assertTrue( Hibernate.isInitialized( n1.getElements() ) );
77+
context.assertTrue( Hibernate.isInitialized( n2.getElements() ) );
7278
} );
7379
} )
7480
)
@@ -91,6 +97,22 @@ public Element(Node node) {
9197

9298
Element() {
9399
}
100+
101+
public Integer getId() {
102+
return id;
103+
}
104+
105+
public void setId(Integer id) {
106+
this.id = id;
107+
}
108+
109+
public Node getNode() {
110+
return node;
111+
}
112+
113+
public void setNode(Node node) {
114+
this.node = node;
115+
}
94116
}
95117

96118
@Entity(name = "Node")
@@ -209,5 +231,85 @@ public boolean equals(Object o) {
209231
public int hashCode() {
210232
return Objects.hash( string );
211233
}
234+
235+
public Integer getVersion() {
236+
return version;
237+
}
238+
239+
public void setVersion(Integer version) {
240+
this.version = version;
241+
}
242+
243+
public Node getParent() {
244+
return parent;
245+
}
246+
247+
public void setParent(Node parent) {
248+
this.parent = parent;
249+
}
250+
251+
public List<Element> getElements() {
252+
return elements;
253+
}
254+
255+
public void setElements(List<Element> elements) {
256+
this.elements = elements;
257+
}
258+
259+
public boolean isPrePersisted() {
260+
return prePersisted;
261+
}
262+
263+
public void setPrePersisted(boolean prePersisted) {
264+
this.prePersisted = prePersisted;
265+
}
266+
267+
public boolean isPostPersisted() {
268+
return postPersisted;
269+
}
270+
271+
public void setPostPersisted(boolean postPersisted) {
272+
this.postPersisted = postPersisted;
273+
}
274+
275+
public boolean isPreUpdated() {
276+
return preUpdated;
277+
}
278+
279+
public void setPreUpdated(boolean preUpdated) {
280+
this.preUpdated = preUpdated;
281+
}
282+
283+
public boolean isPostUpdated() {
284+
return postUpdated;
285+
}
286+
287+
public void setPostUpdated(boolean postUpdated) {
288+
this.postUpdated = postUpdated;
289+
}
290+
291+
public boolean isPostRemoved() {
292+
return postRemoved;
293+
}
294+
295+
public void setPostRemoved(boolean postRemoved) {
296+
this.postRemoved = postRemoved;
297+
}
298+
299+
public boolean isPreRemoved() {
300+
return preRemoved;
301+
}
302+
303+
public void setPreRemoved(boolean preRemoved) {
304+
this.preRemoved = preRemoved;
305+
}
306+
307+
public boolean isLoaded() {
308+
return loaded;
309+
}
310+
311+
public void setLoaded(boolean loaded) {
312+
this.loaded = loaded;
313+
}
212314
}
213315
}

0 commit comments

Comments
 (0)