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