4
4
*/
5
5
package org .hibernate .orm .test .inheritance ;
6
6
7
+ import org .hibernate .testing .jdbc .SQLStatementInspector ;
7
8
import org .hibernate .testing .orm .junit .DomainModel ;
8
9
import org .hibernate .testing .orm .junit .Jira ;
9
10
import org .hibernate .testing .orm .junit .SessionFactory ;
26
27
/**
27
28
* @author Marco Belladelli
28
29
*/
29
- @ SessionFactory
30
+ @ SessionFactory ( useCollectingStatementInspector = true )
30
31
@ DomainModel ( annotatedClasses = {
31
32
JoinedInheritanceTreatQueryTest .Product .class ,
32
33
JoinedInheritanceTreatQueryTest .ProductOwner .class ,
35
36
JoinedInheritanceTreatQueryTest .Description .class ,
36
37
} )
37
38
@ Jira ( "https://hibernate.atlassian.net/browse/HHH-16574" )
39
+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-18745" )
38
40
public class JoinedInheritanceTreatQueryTest {
39
41
@ BeforeAll
40
42
public void setUp (SessionFactoryScope scope ) {
@@ -61,6 +63,8 @@ public void tearDown(SessionFactoryScope scope) {
61
63
62
64
@ Test
63
65
public void testTreatedJoin (SessionFactoryScope scope ) {
66
+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
67
+ inspector .clear ();
64
68
scope .inTransaction ( session -> {
65
69
final Product result = session .createQuery (
66
70
"from Product p " +
@@ -70,11 +74,14 @@ public void testTreatedJoin(SessionFactoryScope scope) {
70
74
).getSingleResult ();
71
75
assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner1 .class );
72
76
assertThat ( ( (ProductOwner1 ) result .getOwner () ).getDescription ().getText () ).isEqualTo ( "description" );
77
+ inspector .assertNumberOfJoins ( 0 , 3 );
73
78
} );
74
79
}
75
80
76
81
@ Test
77
82
public void testImplicitTreatedJoin (SessionFactoryScope scope ) {
83
+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
84
+ inspector .clear ();
78
85
scope .inTransaction ( session -> {
79
86
final Product result = session .createQuery (
80
87
"from Product p " +
@@ -83,11 +90,14 @@ public void testImplicitTreatedJoin(SessionFactoryScope scope) {
83
90
).getSingleResult ();
84
91
assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner1 .class );
85
92
assertThat ( ( (ProductOwner1 ) result .getOwner () ).getDescription ().getText () ).isEqualTo ( "description" );
93
+ inspector .assertNumberOfJoins ( 0 , 3 );
86
94
} );
87
95
}
88
96
89
97
@ Test
90
98
public void testTreatedRoot (SessionFactoryScope scope ) {
99
+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
100
+ inspector .clear ();
91
101
scope .inTransaction ( session -> {
92
102
final ProductOwner result = session .createQuery (
93
103
"from ProductOwner owner " +
@@ -96,11 +106,14 @@ public void testTreatedRoot(SessionFactoryScope scope) {
96
106
).getSingleResult ();
97
107
assertThat ( result ).isInstanceOf ( ProductOwner1 .class );
98
108
assertThat ( ( (ProductOwner1 ) result ).getDescription ().getText () ).isEqualTo ( "description" );
109
+ inspector .assertNumberOfJoins ( 0 , 3 );
99
110
} );
100
111
}
101
112
102
113
@ Test
103
114
public void testTreatedEntityJoin (SessionFactoryScope scope ) {
115
+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
116
+ inspector .clear ();
104
117
scope .inTransaction ( session -> {
105
118
final Product result = session .createQuery (
106
119
"from Product p " +
@@ -110,11 +123,14 @@ public void testTreatedEntityJoin(SessionFactoryScope scope) {
110
123
).getSingleResult ();
111
124
assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner1 .class );
112
125
assertThat ( ( (ProductOwner1 ) result .getOwner () ).getDescription ().getText () ).isEqualTo ( "description" );
126
+ inspector .assertNumberOfJoins ( 0 , 3 );
113
127
} );
114
128
}
115
129
116
130
@ Test
117
131
public void testBasicProperty (SessionFactoryScope scope ) {
132
+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
133
+ inspector .clear ();
118
134
scope .inTransaction ( session -> {
119
135
final Product result = session .createQuery (
120
136
"from Product p " +
@@ -124,6 +140,7 @@ public void testBasicProperty(SessionFactoryScope scope) {
124
140
).getSingleResult ();
125
141
assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner2 .class );
126
142
assertThat ( ( (ProductOwner2 ) result .getOwner () ).getBasicProp () ).isEqualTo ( "basic_prop" );
143
+ inspector .assertNumberOfJoins ( 0 , 2 );
127
144
} );
128
145
}
129
146
0 commit comments