Skip to content

Commit a92e0db

Browse files
mbladelbeikov
authored andcommitted
HHH-18745 Add test for issue
1 parent 69f4951 commit a92e0db

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/inheritance/JoinedInheritanceTreatQueryTest.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.orm.test.inheritance;
88

9+
import org.hibernate.testing.jdbc.SQLStatementInspector;
910
import org.hibernate.testing.orm.junit.DomainModel;
1011
import org.hibernate.testing.orm.junit.Jira;
1112
import org.hibernate.testing.orm.junit.SessionFactory;
@@ -28,7 +29,7 @@
2829
/**
2930
* @author Marco Belladelli
3031
*/
31-
@SessionFactory
32+
@SessionFactory( useCollectingStatementInspector = true )
3233
@DomainModel( annotatedClasses = {
3334
JoinedInheritanceTreatQueryTest.Product.class,
3435
JoinedInheritanceTreatQueryTest.ProductOwner.class,
@@ -37,6 +38,7 @@
3738
JoinedInheritanceTreatQueryTest.Description.class,
3839
} )
3940
@Jira( "https://hibernate.atlassian.net/browse/HHH-16574" )
41+
@Jira( "https://hibernate.atlassian.net/browse/HHH-18745" )
4042
public class JoinedInheritanceTreatQueryTest {
4143
@BeforeAll
4244
public void setUp(SessionFactoryScope scope) {
@@ -63,6 +65,8 @@ public void tearDown(SessionFactoryScope scope) {
6365

6466
@Test
6567
public void testTreatedJoin(SessionFactoryScope scope) {
68+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
69+
inspector.clear();
6670
scope.inTransaction( session -> {
6771
final Product result = session.createQuery(
6872
"from Product p " +
@@ -72,11 +76,14 @@ public void testTreatedJoin(SessionFactoryScope scope) {
7276
).getSingleResult();
7377
assertThat( result.getOwner() ).isInstanceOf( ProductOwner1.class );
7478
assertThat( ( (ProductOwner1) result.getOwner() ).getDescription().getText() ).isEqualTo( "description" );
79+
inspector.assertNumberOfJoins( 0, 3 );
7580
} );
7681
}
7782

7883
@Test
7984
public void testImplicitTreatedJoin(SessionFactoryScope scope) {
85+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
86+
inspector.clear();
8087
scope.inTransaction( session -> {
8188
final Product result = session.createQuery(
8289
"from Product p " +
@@ -85,11 +92,14 @@ public void testImplicitTreatedJoin(SessionFactoryScope scope) {
8592
).getSingleResult();
8693
assertThat( result.getOwner() ).isInstanceOf( ProductOwner1.class );
8794
assertThat( ( (ProductOwner1) result.getOwner() ).getDescription().getText() ).isEqualTo( "description" );
95+
inspector.assertNumberOfJoins( 0, 3 );
8896
} );
8997
}
9098

9199
@Test
92100
public void testTreatedRoot(SessionFactoryScope scope) {
101+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
102+
inspector.clear();
93103
scope.inTransaction( session -> {
94104
final ProductOwner result = session.createQuery(
95105
"from ProductOwner owner " +
@@ -98,11 +108,14 @@ public void testTreatedRoot(SessionFactoryScope scope) {
98108
).getSingleResult();
99109
assertThat( result ).isInstanceOf( ProductOwner1.class );
100110
assertThat( ( (ProductOwner1) result ).getDescription().getText() ).isEqualTo( "description" );
111+
inspector.assertNumberOfJoins( 0, 3 );
101112
} );
102113
}
103114

104115
@Test
105116
public void testTreatedEntityJoin(SessionFactoryScope scope) {
117+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
118+
inspector.clear();
106119
scope.inTransaction( session -> {
107120
final Product result = session.createQuery(
108121
"from Product p " +
@@ -112,11 +125,14 @@ public void testTreatedEntityJoin(SessionFactoryScope scope) {
112125
).getSingleResult();
113126
assertThat( result.getOwner() ).isInstanceOf( ProductOwner1.class );
114127
assertThat( ( (ProductOwner1) result.getOwner() ).getDescription().getText() ).isEqualTo( "description" );
128+
inspector.assertNumberOfJoins( 0, 3 );
115129
} );
116130
}
117131

118132
@Test
119133
public void testBasicProperty(SessionFactoryScope scope) {
134+
final SQLStatementInspector inspector = scope.getCollectingStatementInspector();
135+
inspector.clear();
120136
scope.inTransaction( session -> {
121137
final Product result = session.createQuery(
122138
"from Product p " +
@@ -126,6 +142,7 @@ public void testBasicProperty(SessionFactoryScope scope) {
126142
).getSingleResult();
127143
assertThat( result.getOwner() ).isInstanceOf( ProductOwner2.class );
128144
assertThat( ( (ProductOwner2) result.getOwner() ).getBasicProp() ).isEqualTo( "basic_prop" );
145+
inspector.assertNumberOfJoins( 0, 2 );
129146
} );
130147
}
131148

0 commit comments

Comments
 (0)