Skip to content

Commit c7658e1

Browse files
mbelladebeikov
authored andcommitted
HHH-17615 Small fix to entity joins with soft-delete and inheritance
1 parent b99b6e4 commit c7658e1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.hibernate.HibernateException;
1313
import org.hibernate.Internal;
1414
import org.hibernate.LockMode;
15-
import org.hibernate.boot.model.internal.SoftDeleteHelper;
1615
import org.hibernate.boot.model.process.internal.InferredBasicValueResolver;
1716
import org.hibernate.dialect.Dialect;
1817
import org.hibernate.dialect.DmlTargetColumnQualifierSupport;
@@ -31,7 +30,6 @@
3130
import org.hibernate.id.OptimizableGenerator;
3231
import org.hibernate.id.enhanced.Optimizer;
3332
import org.hibernate.internal.FilterHelper;
34-
import org.hibernate.internal.util.MutableBoolean;
3533
import org.hibernate.internal.util.collections.CollectionHelper;
3634
import org.hibernate.internal.util.collections.Stack;
3735
import org.hibernate.internal.util.collections.StandardStack;
@@ -422,6 +420,7 @@
422420
import java.util.function.Supplier;
423421

424422
import static java.util.Collections.singletonList;
423+
import static org.hibernate.boot.model.internal.SoftDeleteHelper.createNonSoftDeletedRestriction;
425424
import static org.hibernate.generator.EventType.INSERT;
426425
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
427426
import static org.hibernate.query.sqm.BinaryArithmeticOperator.ADD;
@@ -3441,7 +3440,6 @@ private TableGroup consumeCrossJoin(SqmCrossJoin<?> sqmJoin, TableGroup lhsTable
34413440
}
34423441

34433442
private TableGroup consumeEntityJoin(SqmEntityJoin<?> sqmJoin, TableGroup lhsTableGroup, boolean transitive) {
3444-
final MutableBoolean needsTreat = new MutableBoolean( false );
34453443
final EntityPersister entityDescriptor = resolveEntityPersister( sqmJoin.getReferencedPathSource() );
34463444

34473445
final SqlAstJoinType correspondingSqlJoinType = sqmJoin.getSqmJoinType().getCorrespondingSqlJoinType();
@@ -3450,12 +3448,12 @@ private TableGroup consumeEntityJoin(SqmEntityJoin<?> sqmJoin, TableGroup lhsTab
34503448
sqmJoin.getNavigablePath(),
34513449
sqmJoin.getExplicitAlias(),
34523450
null,
3453-
() -> p -> needsTreat.setValue( true ),
3451+
() -> p -> {},
34543452
this
34553453
);
34563454
registerSqmFromTableGroup( sqmJoin, tableGroup );
34573455

3458-
if ( needsTreat.getValue() ) {
3456+
if ( entityDescriptor.isInherited() && !sqmJoin.hasTreats() ) {
34593457
// Register new treat to apply the discriminator condition to the table reference itself, see #pruneTableGroupJoins
34603458
registerEntityNameUsage( tableGroup, EntityNameUse.TREAT, entityDescriptor.getEntityName() );
34613459
}
@@ -3479,8 +3477,8 @@ private TableGroup consumeEntityJoin(SqmEntityJoin<?> sqmJoin, TableGroup lhsTab
34793477

34803478
final SoftDeleteMapping softDeleteMapping = entityDescriptor.getSoftDeleteMapping();
34813479
if ( softDeleteMapping != null ) {
3482-
final Predicate softDeleteRestriction = SoftDeleteHelper.createNonSoftDeletedRestriction(
3483-
tableGroup.resolveTableReference( entityDescriptor.getSoftDeleteTableDetails().getTableName() ),
3480+
final Predicate softDeleteRestriction = createNonSoftDeletedRestriction(
3481+
tableGroup.resolveTableReference( softDeleteMapping.getTableName() ),
34843482
softDeleteMapping
34853483
);
34863484
tableGroupJoin.applyPredicate( softDeleteRestriction );

0 commit comments

Comments
 (0)