Skip to content

Commit 27a9ec2

Browse files
committed
HHH-17826 Add test for issue
1 parent b300b9d commit 27a9ec2

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package org.hibernate.orm.test.iterate;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.hibernate.ScrollMode;
7+
import org.hibernate.ScrollableResults;
8+
import org.hibernate.query.spi.QueryImplementor;
9+
10+
import org.hibernate.testing.orm.junit.DomainModel;
11+
import org.hibernate.testing.orm.junit.Jira;
12+
import org.hibernate.testing.orm.junit.SessionFactory;
13+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
14+
import org.junit.jupiter.api.BeforeAll;
15+
import org.junit.jupiter.api.Test;
16+
17+
import jakarta.persistence.Entity;
18+
import jakarta.persistence.FetchType;
19+
import jakarta.persistence.GeneratedValue;
20+
import jakarta.persistence.Id;
21+
import jakarta.persistence.ManyToOne;
22+
import jakarta.persistence.OneToMany;
23+
24+
@DomainModel(
25+
annotatedClasses = {
26+
ForwardOnlyScrollNoTransactionTest.Father.class,
27+
ForwardOnlyScrollNoTransactionTest.Son.class
28+
}
29+
)
30+
@SessionFactory
31+
@Jira("HHH-17826")
32+
public class ForwardOnlyScrollNoTransactionTest {
33+
34+
@BeforeAll
35+
public void setUp(SessionFactoryScope scope) {
36+
scope.inTransaction(
37+
session -> {
38+
Son son = new Son( "Andrea" );
39+
Father father = new Father( "Lionello" );
40+
father.addSon( son );
41+
session.persist( father );
42+
43+
Son son1 = new Son( "Alberto" );
44+
Father father1 = new Father( "Roberto" );
45+
father1.addSon( son1 );
46+
session.persist( father1 );
47+
}
48+
);
49+
}
50+
51+
@Test
52+
public void testScroll(SessionFactoryScope scope) {
53+
scope.inSession(
54+
session -> {
55+
QueryImplementor query = session.createQuery( "select f from Father f" );
56+
57+
try (ScrollableResults result = query.scroll( ScrollMode.FORWARD_ONLY )) {
58+
while ( result.next() ) {
59+
result.get();
60+
}
61+
}
62+
}
63+
);
64+
}
65+
66+
@Entity(name = "Father")
67+
public static class Father {
68+
@Id
69+
@GeneratedValue
70+
private Integer id;
71+
72+
private String name;
73+
74+
@OneToMany(mappedBy = "father", fetch = FetchType.EAGER)
75+
public List<Son> sons = new ArrayList<>();
76+
77+
public Father() {
78+
}
79+
80+
public Father(String name) {
81+
this.name = name;
82+
}
83+
84+
public void addSon(Son son) {
85+
sons.add( son );
86+
son.father = this;
87+
}
88+
}
89+
90+
@Entity(name = "Son")
91+
public static class Son {
92+
@Id
93+
@GeneratedValue
94+
private Integer id;
95+
96+
private String name;
97+
98+
@ManyToOne
99+
private Father father;
100+
101+
public Son() {
102+
}
103+
104+
public Son(String name) {
105+
this.name = name;
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)