9
9
import org .hibernate .Session ;
10
10
import org .hibernate .query .Query ;
11
11
12
- import org .hibernate .testing .TestForIssue ;
13
12
import org .hibernate .testing .orm .junit .DomainModel ;
13
+ import org .hibernate .testing .orm .junit .JiraKey ;
14
14
import org .hibernate .testing .orm .junit .SessionFactory ;
15
15
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
16
16
21
21
import jakarta .persistence .Entity ;
22
22
import jakarta .persistence .GeneratedValue ;
23
23
import jakarta .persistence .Id ;
24
+ import jakarta .persistence .Inheritance ;
25
+ import jakarta .persistence .InheritanceType ;
24
26
25
27
import static org .assertj .core .api .Assertions .assertThat ;
26
28
27
29
@ DomainModel (
28
30
annotatedClasses = {
29
31
DeleteWhereFunctionCallTest .SuperType .class ,
30
- DeleteWhereFunctionCallTest .SubType .class
32
+ DeleteWhereFunctionCallTest .SubType .class ,
33
+ DeleteWhereFunctionCallTest .TablePerClassSuperType .class ,
34
+ DeleteWhereFunctionCallTest .TablePerClassSubType .class ,
31
35
}
32
36
)
33
37
@ SessionFactory
@@ -38,6 +42,8 @@ public void initData(SessionFactoryScope scope) {
38
42
scope .inTransaction ( s -> {
39
43
s .persist ( new SuperType ( -1 ) );
40
44
s .persist ( new SubType ( -2 ) );
45
+ s .persist ( new TablePerClassSuperType ( -1 ) );
46
+ s .persist ( new TablePerClassSubType ( -2 ) );
41
47
} );
42
48
}
43
49
@@ -47,20 +53,22 @@ public void tearDown(SessionFactoryScope scope){
47
53
session -> {
48
54
session .createQuery ( "delete from supert" ).executeUpdate ();
49
55
session .createQuery ( "delete from subt" ).executeUpdate ();
56
+ session .createQuery ( "delete from tpc_supert" ).executeUpdate ();
57
+ session .createQuery ( "delete from tpc_subt" ).executeUpdate ();
50
58
}
51
59
);
52
60
}
53
61
54
62
@ Test
55
- @ TestForIssue ( jiraKey = "HHH-14814" )
63
+ @ JiraKey ( "HHH-14814" )
56
64
public void testDeleteWhereTypeFunctionCall (SessionFactoryScope scope ) {
57
65
scope .inTransaction ( s -> {
58
66
assertThat ( count ( s , SuperType .class ) ).isEqualTo ( 2 );
59
67
assertThat ( count ( s , SubType .class ) ).isEqualTo ( 1 );
60
68
} );
61
69
scope .inTransaction ( s -> {
62
70
Query <?> query = s .createQuery ( "delete from " + SuperType .class .getName () + " e"
63
- + " where type( e ) = :type" );
71
+ + " where type( e ) = :type" );
64
72
query .setParameter ( "type" , SuperType .class );
65
73
query .executeUpdate ();
66
74
} );
@@ -70,6 +78,25 @@ public void testDeleteWhereTypeFunctionCall(SessionFactoryScope scope) {
70
78
} );
71
79
}
72
80
81
+ @ Test
82
+ @ JiraKey ("HHH-16897" )
83
+ public void testDeleteWhereTypeFunctionCallWithTablePerClassInheritance (SessionFactoryScope scope ) {
84
+ scope .inTransaction ( s -> {
85
+ assertThat ( count ( s , TablePerClassSuperType .class ) ).isEqualTo ( 2 );
86
+ assertThat ( count ( s , TablePerClassSubType .class ) ).isEqualTo ( 1 );
87
+ } );
88
+ scope .inTransaction ( s -> {
89
+ Query <?> query = s .createQuery ( "delete from " + TablePerClassSuperType .class .getName () + " e"
90
+ + " where type( e ) = :type" );
91
+ query .setParameter ( "type" , TablePerClassSuperType .class );
92
+ query .executeUpdate ();
93
+ } );
94
+ scope .inTransaction ( s -> {
95
+ assertThat ( count ( s , TablePerClassSuperType .class ) ).isEqualTo ( 1 );
96
+ assertThat ( count ( s , TablePerClassSubType .class ) ).isEqualTo ( 1 );
97
+ } );
98
+ }
99
+
73
100
@ Test
74
101
public void testDeleteWhereAbsFunctionCall (SessionFactoryScope scope ) {
75
102
scope .inTransaction ( s -> {
@@ -118,4 +145,31 @@ public SubType(int someNumber) {
118
145
super ( someNumber );
119
146
}
120
147
}
148
+
149
+ @ Entity (name = "tpc_supert" )
150
+ @ Inheritance (strategy = InheritanceType .TABLE_PER_CLASS )
151
+ public static class TablePerClassSuperType {
152
+ @ Id
153
+ @ GeneratedValue
154
+ private Long id ;
155
+
156
+ private int someNumber ;
157
+
158
+ public TablePerClassSuperType () {
159
+ }
160
+
161
+ public TablePerClassSuperType (int someNumber ) {
162
+ this .someNumber = someNumber ;
163
+ }
164
+ }
165
+
166
+ @ Entity (name = "tpc_subt" )
167
+ public static class TablePerClassSubType extends TablePerClassSuperType {
168
+ public TablePerClassSubType () {
169
+ }
170
+
171
+ public TablePerClassSubType (int someNumber ) {
172
+ super ( someNumber );
173
+ }
174
+ }
121
175
}
0 commit comments