HHH-17143 - Bad handling of not-found association references in mutation queries

https://hibernate.atlassian.net/browse/HHH-17143
This commit is contained in:
Steve Ebersole 2023-08-28 16:48:21 -05:00
parent 8ddc6e5105
commit 1979aed658
1 changed files with 34 additions and 0 deletions

View File

@ -14,6 +14,8 @@ import org.hibernate.annotations.NotFoundAction;
import org.hibernate.testing.jdbc.SQLStatementInspector;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.AfterEach;
@ -135,6 +137,38 @@ public class NotFoundTest {
);
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17143" )
@FailureExpected
void testHqlDelete(EntityManagerFactoryScope scope) {
breakForeignKey( scope );
final SQLStatementInspector sqlStatementInspector = scope.getCollectingStatementInspector();
sqlStatementInspector.clear();
scope.inTransaction( (entityManager) -> {
entityManager.createQuery( "delete from Person p where p.city is null" ).executeUpdate();
assertThat( sqlStatementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( sqlStatementInspector.getSqlQueries().get( 0 ) ).doesNotContainIgnoringCase( "city_fk is null" );
} );
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17143" )
@FailureExpected
void testHqlUpdate(EntityManagerFactoryScope scope) {
breakForeignKey( scope );
final SQLStatementInspector sqlStatementInspector = scope.getCollectingStatementInspector();
sqlStatementInspector.clear();
scope.inTransaction( (entityManager) -> {
entityManager.createQuery( "update Person p set p.name = 'abc' where p.city is null" ).executeUpdate();
assertThat( sqlStatementInspector.getSqlQueries() ).hasSize( 1 );
assertThat( sqlStatementInspector.getSqlQueries().get( 0 ) ).doesNotContainIgnoringCase( "city_fk is null" );
} );
}
private void breakForeignKey(EntityManagerFactoryScope scope) {
scope.inTransaction(
entityManager -> {