9
9
import java .util .ArrayList ;
10
10
import java .util .Arrays ;
11
11
import java .util .List ;
12
+
13
+ import org .hibernate .query .spi .QueryImplementor ;
14
+
15
+ import org .hibernate .testing .TestForIssue ;
16
+ import org .hibernate .testing .orm .junit .DomainModel ;
17
+ import org .hibernate .testing .orm .junit .SessionFactory ;
18
+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
19
+ import org .junit .jupiter .api .AfterEach ;
20
+ import org .junit .jupiter .api .BeforeAll ;
21
+ import org .junit .jupiter .api .BeforeEach ;
22
+ import org .junit .jupiter .api .Test ;
23
+
12
24
import jakarta .persistence .CascadeType ;
13
25
import jakarta .persistence .DiscriminatorColumn ;
14
26
import jakarta .persistence .DiscriminatorType ;
21
33
import jakarta .persistence .OneToMany ;
22
34
import jakarta .persistence .OneToOne ;
23
35
24
- import org .hibernate .testing .TestForIssue ;
25
- import org .hibernate .testing .orm .junit .DomainModel ;
26
- import org .hibernate .testing .orm .junit .SessionFactory ;
27
- import org .hibernate .testing .orm .junit .SessionFactoryScope ;
28
- import org .junit .jupiter .api .BeforeEach ;
29
- import org .junit .jupiter .api .Test ;
30
-
31
36
import static org .hamcrest .MatcherAssert .assertThat ;
32
37
import static org .hamcrest .core .Is .is ;
33
38
import static org .junit .jupiter .api .Assertions .fail ;
@@ -56,7 +61,7 @@ public class SingleTableInheritancePersistTest {
56
61
private final List <Child > children = new ArrayList <>( Arrays .asList ( susan , mark ) );
57
62
private final List <Person > familyMembers = Arrays .asList ( john , jane , susan , mark );
58
63
59
- @ BeforeEach
64
+ @ BeforeAll
60
65
public void setUp (SessionFactoryScope scope ) {
61
66
scope .inTransaction (
62
67
session -> {
@@ -77,7 +82,6 @@ public void setUp(SessionFactoryScope scope) {
77
82
78
83
session .persist ( family );
79
84
} );
80
-
81
85
}
82
86
83
87
@ Test
@@ -109,6 +113,28 @@ else if ( person instanceof Child ) {
109
113
} );
110
114
}
111
115
116
+ @ Test
117
+ @ TestForIssue (jiraKey = "HHH-15497" )
118
+ public void testFetchChildrenCountTwiceFails (SessionFactoryScope scope ) {
119
+ scope .inTransaction (
120
+ session -> {
121
+ QueryImplementor <Long > query = session .createQuery (
122
+ "SELECT count(p) FROM Person p WHERE TYPE(p) = ?1" ,
123
+ Long .class
124
+ );
125
+ query .setParameter ( 1 , Child .class );
126
+ Long personCount = query .getSingleResult ();
127
+
128
+ assertThat ( personCount , is ( 2L ) );
129
+
130
+ query = session .createQuery ( "SELECT count(p) FROM Person p WHERE TYPE(p) = ?1" , Long .class );
131
+ query .setParameter ( 1 , Child .class );
132
+ personCount = query .getSingleResult ();
133
+
134
+ assertThat ( personCount , is ( 2L ) );
135
+ } );
136
+ }
137
+
112
138
@ Entity (name = "Family" )
113
139
public static class Family {
114
140
0 commit comments