HHH-17615 Fix pruning of soft delete table for joined inheritance

This commit is contained in:
Marco Belladelli 2024-01-09 11:14:16 +01:00 committed by Christian Beikov
parent 6827581a38
commit b99b6e4146
2 changed files with 23 additions and 1 deletions

View File

@ -3117,6 +3117,10 @@ public abstract class AbstractEntityPersister
creationState.getSqlExpressionResolver()
);
additionalPredicateCollectorAccess.get().accept( softDeletePredicate );
if ( tableReference != rootTableReference && creationState.supportsEntityNameUsage() ) {
// Register entity name usage for the hierarchy root table to avoid pruning
creationState.registerEntityNameUsage( tableGroup, EntityNameUse.EXPRESSION, getRootEntityName() );
}
}
}

View File

@ -12,6 +12,7 @@ import java.util.List;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
@ -55,11 +56,28 @@ public class JoinedSubclassSoftDeleteTests {
scope.inTransaction( (session) -> {
// should not return #1
assertThat( session.createQuery( "from JoinedRoot" ).list() ).hasSize( 2 );
assertThat( session.createQuery( "from JoinedRoot where id = 1" ).list() ).isEmpty();
} );
scope.inTransaction( (session) -> {
// should not return #1
assertThat( session.createQuery( "from JoinedSub" ).list() ).hasSize( 2 );
assertThat( session.createQuery( "from JoinedSub where id = 1" ).list() ).isEmpty();
} );
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17615" )
void testCountQuery(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
// should not return #1
assertThat( session.createQuery( "select count(*) from JoinedRoot" ).uniqueResult() ).isEqualTo( 2L );
assertThat( session.createQuery( "select count(*) from JoinedRoot where id = 1" ).uniqueResult() ).isEqualTo( 0L );
} );
scope.inTransaction( (session) -> {
// should not return #1
assertThat( session.createQuery( "select count(*) from JoinedSub" ).uniqueResult() ).isEqualTo( 2L );
assertThat( session.createQuery( "select count(*) from JoinedSub where id = 1" ).uniqueResult() ).isEqualTo( 0L );
} );
}