Skip to content

Commit 7af0642

Browse files
committed
HHH-15497 Add test for issue
1 parent 1237977 commit 7af0642

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/discriminator/SingleTableInheritancePersistTest.java

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
import java.util.ArrayList;
1010
import java.util.Arrays;
1111
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+
1224
import jakarta.persistence.CascadeType;
1325
import jakarta.persistence.DiscriminatorColumn;
1426
import jakarta.persistence.DiscriminatorType;
@@ -21,13 +33,6 @@
2133
import jakarta.persistence.OneToMany;
2234
import jakarta.persistence.OneToOne;
2335

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-
3136
import static org.hamcrest.MatcherAssert.assertThat;
3237
import static org.hamcrest.core.Is.is;
3338
import static org.junit.jupiter.api.Assertions.fail;
@@ -56,7 +61,7 @@ public class SingleTableInheritancePersistTest {
5661
private final List<Child> children = new ArrayList<>( Arrays.asList( susan, mark ) );
5762
private final List<Person> familyMembers = Arrays.asList( john, jane, susan, mark );
5863

59-
@BeforeEach
64+
@BeforeAll
6065
public void setUp(SessionFactoryScope scope) {
6166
scope.inTransaction(
6267
session -> {
@@ -77,7 +82,6 @@ public void setUp(SessionFactoryScope scope) {
7782

7883
session.persist( family );
7984
} );
80-
8185
}
8286

8387
@Test
@@ -109,6 +113,28 @@ else if ( person instanceof Child ) {
109113
} );
110114
}
111115

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+
112138
@Entity(name = "Family")
113139
public static class Family {
114140

0 commit comments

Comments
 (0)