44 */
55package org .hibernate .orm .test .inheritance ;
66
7+ import org .hibernate .testing .jdbc .SQLStatementInspector ;
78import org .hibernate .testing .orm .junit .DomainModel ;
89import org .hibernate .testing .orm .junit .Jira ;
910import org .hibernate .testing .orm .junit .SessionFactory ;
2627/**
2728 * @author Marco Belladelli
2829 */
29- @ SessionFactory
30+ @ SessionFactory ( useCollectingStatementInspector = true )
3031@ DomainModel ( annotatedClasses = {
3132 JoinedInheritanceTreatQueryTest .Product .class ,
3233 JoinedInheritanceTreatQueryTest .ProductOwner .class ,
3536 JoinedInheritanceTreatQueryTest .Description .class ,
3637} )
3738@ Jira ( "https://hibernate.atlassian.net/browse/HHH-16574" )
39+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-18745" )
3840public class JoinedInheritanceTreatQueryTest {
3941 @ BeforeAll
4042 public void setUp (SessionFactoryScope scope ) {
@@ -61,6 +63,8 @@ public void tearDown(SessionFactoryScope scope) {
6163
6264 @ Test
6365 public void testTreatedJoin (SessionFactoryScope scope ) {
66+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
67+ inspector .clear ();
6468 scope .inTransaction ( session -> {
6569 final Product result = session .createQuery (
6670 "from Product p " +
@@ -70,11 +74,14 @@ public void testTreatedJoin(SessionFactoryScope scope) {
7074 ).getSingleResult ();
7175 assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner1 .class );
7276 assertThat ( ( (ProductOwner1 ) result .getOwner () ).getDescription ().getText () ).isEqualTo ( "description" );
77+ inspector .assertNumberOfJoins ( 0 , 3 );
7378 } );
7479 }
7580
7681 @ Test
7782 public void testImplicitTreatedJoin (SessionFactoryScope scope ) {
83+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
84+ inspector .clear ();
7885 scope .inTransaction ( session -> {
7986 final Product result = session .createQuery (
8087 "from Product p " +
@@ -83,11 +90,14 @@ public void testImplicitTreatedJoin(SessionFactoryScope scope) {
8390 ).getSingleResult ();
8491 assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner1 .class );
8592 assertThat ( ( (ProductOwner1 ) result .getOwner () ).getDescription ().getText () ).isEqualTo ( "description" );
93+ inspector .assertNumberOfJoins ( 0 , 3 );
8694 } );
8795 }
8896
8997 @ Test
9098 public void testTreatedRoot (SessionFactoryScope scope ) {
99+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
100+ inspector .clear ();
91101 scope .inTransaction ( session -> {
92102 final ProductOwner result = session .createQuery (
93103 "from ProductOwner owner " +
@@ -96,11 +106,14 @@ public void testTreatedRoot(SessionFactoryScope scope) {
96106 ).getSingleResult ();
97107 assertThat ( result ).isInstanceOf ( ProductOwner1 .class );
98108 assertThat ( ( (ProductOwner1 ) result ).getDescription ().getText () ).isEqualTo ( "description" );
109+ inspector .assertNumberOfJoins ( 0 , 3 );
99110 } );
100111 }
101112
102113 @ Test
103114 public void testTreatedEntityJoin (SessionFactoryScope scope ) {
115+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
116+ inspector .clear ();
104117 scope .inTransaction ( session -> {
105118 final Product result = session .createQuery (
106119 "from Product p " +
@@ -110,11 +123,14 @@ public void testTreatedEntityJoin(SessionFactoryScope scope) {
110123 ).getSingleResult ();
111124 assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner1 .class );
112125 assertThat ( ( (ProductOwner1 ) result .getOwner () ).getDescription ().getText () ).isEqualTo ( "description" );
126+ inspector .assertNumberOfJoins ( 0 , 3 );
113127 } );
114128 }
115129
116130 @ Test
117131 public void testBasicProperty (SessionFactoryScope scope ) {
132+ final SQLStatementInspector inspector = scope .getCollectingStatementInspector ();
133+ inspector .clear ();
118134 scope .inTransaction ( session -> {
119135 final Product result = session .createQuery (
120136 "from Product p " +
@@ -124,6 +140,7 @@ public void testBasicProperty(SessionFactoryScope scope) {
124140 ).getSingleResult ();
125141 assertThat ( result .getOwner () ).isInstanceOf ( ProductOwner2 .class );
126142 assertThat ( ( (ProductOwner2 ) result .getOwner () ).getBasicProp () ).isEqualTo ( "basic_prop" );
143+ inspector .assertNumberOfJoins ( 0 , 2 );
127144 } );
128145 }
129146
0 commit comments