HHH-16897 Add a test case to reproduce the issue
This commit is contained in:
parent
68dd43c11c
commit
21f2f24bb7
|
@ -9,8 +9,8 @@ package org.hibernate.orm.test.hql;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.query.Query;
|
import org.hibernate.query.Query;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.JiraKey;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
|
||||||
|
@ -21,13 +21,17 @@ import org.junit.jupiter.api.Test;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Inheritance;
|
||||||
|
import jakarta.persistence.InheritanceType;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@DomainModel(
|
@DomainModel(
|
||||||
annotatedClasses = {
|
annotatedClasses = {
|
||||||
DeleteWhereFunctionCallTest.SuperType.class,
|
DeleteWhereFunctionCallTest.SuperType.class,
|
||||||
DeleteWhereFunctionCallTest.SubType.class
|
DeleteWhereFunctionCallTest.SubType.class,
|
||||||
|
DeleteWhereFunctionCallTest.TablePerClassSuperType.class,
|
||||||
|
DeleteWhereFunctionCallTest.TablePerClassSubType.class,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
|
@ -38,6 +42,8 @@ public class DeleteWhereFunctionCallTest {
|
||||||
scope.inTransaction( s -> {
|
scope.inTransaction( s -> {
|
||||||
s.persist( new SuperType( -1 ) );
|
s.persist( new SuperType( -1 ) );
|
||||||
s.persist( new SubType( -2 ) );
|
s.persist( new SubType( -2 ) );
|
||||||
|
s.persist( new TablePerClassSuperType( -1 ) );
|
||||||
|
s.persist( new TablePerClassSubType( -2 ) );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +53,14 @@ public class DeleteWhereFunctionCallTest {
|
||||||
session -> {
|
session -> {
|
||||||
session.createQuery( "delete from supert" ).executeUpdate();
|
session.createQuery( "delete from supert" ).executeUpdate();
|
||||||
session.createQuery( "delete from subt" ).executeUpdate();
|
session.createQuery( "delete from subt" ).executeUpdate();
|
||||||
|
session.createQuery( "delete from tpc_supert" ).executeUpdate();
|
||||||
|
session.createQuery( "delete from tpc_subt" ).executeUpdate();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-14814")
|
@JiraKey("HHH-14814")
|
||||||
public void testDeleteWhereTypeFunctionCall(SessionFactoryScope scope) {
|
public void testDeleteWhereTypeFunctionCall(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( s -> {
|
scope.inTransaction( s -> {
|
||||||
assertThat( count( s, SuperType.class ) ).isEqualTo( 2 );
|
assertThat( count( s, SuperType.class ) ).isEqualTo( 2 );
|
||||||
|
@ -60,7 +68,7 @@ public class DeleteWhereFunctionCallTest {
|
||||||
} );
|
} );
|
||||||
scope.inTransaction( s -> {
|
scope.inTransaction( s -> {
|
||||||
Query<?> query = s.createQuery( "delete from " + SuperType.class.getName() + " e"
|
Query<?> query = s.createQuery( "delete from " + SuperType.class.getName() + " e"
|
||||||
+ " where type( e ) = :type" );
|
+ " where type( e ) = :type" );
|
||||||
query.setParameter( "type", SuperType.class );
|
query.setParameter( "type", SuperType.class );
|
||||||
query.executeUpdate();
|
query.executeUpdate();
|
||||||
} );
|
} );
|
||||||
|
@ -70,6 +78,25 @@ public class DeleteWhereFunctionCallTest {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@JiraKey("HHH-16897")
|
||||||
|
public void testDeleteWhereTypeFunctionCallWithTablePerClassInheritance(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( s -> {
|
||||||
|
assertThat( count( s, TablePerClassSuperType.class ) ).isEqualTo( 2 );
|
||||||
|
assertThat( count( s, TablePerClassSubType.class ) ).isEqualTo( 1 );
|
||||||
|
} );
|
||||||
|
scope.inTransaction( s -> {
|
||||||
|
Query<?> query = s.createQuery( "delete from " + TablePerClassSuperType.class.getName() + " e"
|
||||||
|
+ " where type( e ) = :type" );
|
||||||
|
query.setParameter( "type", TablePerClassSuperType.class );
|
||||||
|
query.executeUpdate();
|
||||||
|
} );
|
||||||
|
scope.inTransaction( s -> {
|
||||||
|
assertThat( count( s, TablePerClassSuperType.class ) ).isEqualTo( 1 );
|
||||||
|
assertThat( count( s, TablePerClassSubType.class ) ).isEqualTo( 1 );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteWhereAbsFunctionCall(SessionFactoryScope scope) {
|
public void testDeleteWhereAbsFunctionCall(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( s -> {
|
scope.inTransaction( s -> {
|
||||||
|
@ -118,4 +145,31 @@ public class DeleteWhereFunctionCallTest {
|
||||||
super( someNumber );
|
super( someNumber );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity(name = "tpc_supert")
|
||||||
|
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||||
|
public static class TablePerClassSuperType {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private int someNumber;
|
||||||
|
|
||||||
|
public TablePerClassSuperType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TablePerClassSuperType(int someNumber) {
|
||||||
|
this.someNumber = someNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity(name = "tpc_subt")
|
||||||
|
public static class TablePerClassSubType extends TablePerClassSuperType {
|
||||||
|
public TablePerClassSubType() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public TablePerClassSubType(int someNumber) {
|
||||||
|
super( someNumber );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue