Skip to content

Commit b99b6e4

Browse files
mbelladebeikov
authored andcommitted
HHH-17615 Fix pruning of soft delete table for joined inheritance
1 parent 6827581 commit b99b6e4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3117,6 +3117,10 @@ public TableGroup createRootTableGroup(
31173117
creationState.getSqlExpressionResolver()
31183118
);
31193119
additionalPredicateCollectorAccess.get().accept( softDeletePredicate );
3120+
if ( tableReference != rootTableReference && creationState.supportsEntityNameUsage() ) {
3121+
// Register entity name usage for the hierarchy root table to avoid pruning
3122+
creationState.registerEntityNameUsage( tableGroup, EntityNameUse.EXPRESSION, getRootEntityName() );
3123+
}
31203124
}
31213125
}
31223126

hibernate-core/src/test/java/org/hibernate/orm/test/softdelete/secondary/JoinedSubclassSoftDeleteTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.ObjectNotFoundException;
1313

1414
import org.hibernate.testing.orm.junit.DomainModel;
15+
import org.hibernate.testing.orm.junit.Jira;
1516
import org.hibernate.testing.orm.junit.SessionFactory;
1617
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1718
import org.junit.jupiter.api.AfterEach;
@@ -55,11 +56,28 @@ void testSelectionQuery(SessionFactoryScope scope) {
5556
scope.inTransaction( (session) -> {
5657
// should not return #1
5758
assertThat( session.createQuery( "from JoinedRoot" ).list() ).hasSize( 2 );
59+
assertThat( session.createQuery( "from JoinedRoot where id = 1" ).list() ).isEmpty();
5860
} );
5961

6062
scope.inTransaction( (session) -> {
6163
// should not return #1
62-
assertThat( session.createQuery( "from JoinedSub" ).list() ).hasSize( 2 );
64+
assertThat( session.createQuery( "from JoinedSub where id = 1" ).list() ).isEmpty();
65+
} );
66+
}
67+
68+
@Test
69+
@Jira( "https://hibernate.atlassian.net/browse/HHH-17615" )
70+
void testCountQuery(SessionFactoryScope scope) {
71+
scope.inTransaction( (session) -> {
72+
// should not return #1
73+
assertThat( session.createQuery( "select count(*) from JoinedRoot" ).uniqueResult() ).isEqualTo( 2L );
74+
assertThat( session.createQuery( "select count(*) from JoinedRoot where id = 1" ).uniqueResult() ).isEqualTo( 0L );
75+
} );
76+
77+
scope.inTransaction( (session) -> {
78+
// should not return #1
79+
assertThat( session.createQuery( "select count(*) from JoinedSub" ).uniqueResult() ).isEqualTo( 2L );
80+
assertThat( session.createQuery( "select count(*) from JoinedSub where id = 1" ).uniqueResult() ).isEqualTo( 0L );
6381
} );
6482
}
6583

0 commit comments

Comments
 (0)