Skip to content

Commit b8ca38e

Browse files
marko-bekhtabeikov
authored andcommitted
HHH-16897 Add a test case to reproduce the issue
1 parent 3b3ed55 commit b8ca38e

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/hql/DeleteWhereFunctionCallTest.java

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import org.hibernate.Session;
1010
import org.hibernate.query.Query;
1111

12-
import org.hibernate.testing.TestForIssue;
1312
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.JiraKey;
1414
import org.hibernate.testing.orm.junit.SessionFactory;
1515
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1616

@@ -21,13 +21,17 @@
2121
import jakarta.persistence.Entity;
2222
import jakarta.persistence.GeneratedValue;
2323
import jakarta.persistence.Id;
24+
import jakarta.persistence.Inheritance;
25+
import jakarta.persistence.InheritanceType;
2426

2527
import static org.assertj.core.api.Assertions.assertThat;
2628

2729
@DomainModel(
2830
annotatedClasses = {
2931
DeleteWhereFunctionCallTest.SuperType.class,
30-
DeleteWhereFunctionCallTest.SubType.class
32+
DeleteWhereFunctionCallTest.SubType.class,
33+
DeleteWhereFunctionCallTest.TablePerClassSuperType.class,
34+
DeleteWhereFunctionCallTest.TablePerClassSubType.class,
3135
}
3236
)
3337
@SessionFactory
@@ -38,6 +42,8 @@ public void initData(SessionFactoryScope scope) {
3842
scope.inTransaction( s -> {
3943
s.persist( new SuperType( -1 ) );
4044
s.persist( new SubType( -2 ) );
45+
s.persist( new TablePerClassSuperType( -1 ) );
46+
s.persist( new TablePerClassSubType( -2 ) );
4147
} );
4248
}
4349

@@ -47,20 +53,22 @@ public void tearDown(SessionFactoryScope scope){
4753
session -> {
4854
session.createQuery( "delete from supert" ).executeUpdate();
4955
session.createQuery( "delete from subt" ).executeUpdate();
56+
session.createQuery( "delete from tpc_supert" ).executeUpdate();
57+
session.createQuery( "delete from tpc_subt" ).executeUpdate();
5058
}
5159
);
5260
}
5361

5462
@Test
55-
@TestForIssue(jiraKey = "HHH-14814")
63+
@JiraKey("HHH-14814")
5664
public void testDeleteWhereTypeFunctionCall(SessionFactoryScope scope) {
5765
scope.inTransaction( s -> {
5866
assertThat( count( s, SuperType.class ) ).isEqualTo( 2 );
5967
assertThat( count( s, SubType.class ) ).isEqualTo( 1 );
6068
} );
6169
scope.inTransaction( s -> {
6270
Query<?> query = s.createQuery( "delete from " + SuperType.class.getName() + " e"
63-
+ " where type( e ) = :type" );
71+
+ " where type( e ) = :type" );
6472
query.setParameter( "type", SuperType.class );
6573
query.executeUpdate();
6674
} );
@@ -70,6 +78,25 @@ public void testDeleteWhereTypeFunctionCall(SessionFactoryScope scope) {
7078
} );
7179
}
7280

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+
73100
@Test
74101
public void testDeleteWhereAbsFunctionCall(SessionFactoryScope scope) {
75102
scope.inTransaction( s -> {
@@ -118,4 +145,31 @@ public SubType(int someNumber) {
118145
super( someNumber );
119146
}
120147
}
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+
}
121175
}

0 commit comments

Comments
 (0)