66 */
77package org .hibernate .orm .test .inheritance ;
88
9+ import org .hibernate .testing .jdbc .SQLStatementInspector ;
910import org .hibernate .testing .orm .junit .DomainModel ;
1011import org .hibernate .testing .orm .junit .Jira ;
1112import org .hibernate .testing .orm .junit .SessionFactory ;
2829/**
2930 * @author Marco Belladelli
3031 */
31- @ SessionFactory
32+ @ SessionFactory ( useCollectingStatementInspector = true )
3233@ DomainModel ( annotatedClasses = {
3334 JoinedInheritanceTreatQueryTest .Product .class ,
3435 JoinedInheritanceTreatQueryTest .ProductOwner .class ,
3738 JoinedInheritanceTreatQueryTest .Description .class ,
3839} )
3940@ Jira ( "https://hibernate.atlassian.net/browse/HHH-16574" )
41+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-18745" )
4042public 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