12
12
import org .hibernate .HibernateException ;
13
13
import org .hibernate .Internal ;
14
14
import org .hibernate .LockMode ;
15
- import org .hibernate .boot .model .internal .SoftDeleteHelper ;
16
15
import org .hibernate .boot .model .process .internal .InferredBasicValueResolver ;
17
16
import org .hibernate .dialect .Dialect ;
18
17
import org .hibernate .dialect .DmlTargetColumnQualifierSupport ;
31
30
import org .hibernate .id .OptimizableGenerator ;
32
31
import org .hibernate .id .enhanced .Optimizer ;
33
32
import org .hibernate .internal .FilterHelper ;
34
- import org .hibernate .internal .util .MutableBoolean ;
35
33
import org .hibernate .internal .util .collections .CollectionHelper ;
36
34
import org .hibernate .internal .util .collections .Stack ;
37
35
import org .hibernate .internal .util .collections .StandardStack ;
422
420
import java .util .function .Supplier ;
423
421
424
422
import static java .util .Collections .singletonList ;
423
+ import static org .hibernate .boot .model .internal .SoftDeleteHelper .createNonSoftDeletedRestriction ;
425
424
import static org .hibernate .generator .EventType .INSERT ;
426
425
import static org .hibernate .internal .util .NullnessHelper .coalesceSuppliedValues ;
427
426
import static org .hibernate .query .sqm .BinaryArithmeticOperator .ADD ;
@@ -3441,7 +3440,6 @@ private TableGroup consumeCrossJoin(SqmCrossJoin<?> sqmJoin, TableGroup lhsTable
3441
3440
}
3442
3441
3443
3442
private TableGroup consumeEntityJoin (SqmEntityJoin <?> sqmJoin , TableGroup lhsTableGroup , boolean transitive ) {
3444
- final MutableBoolean needsTreat = new MutableBoolean ( false );
3445
3443
final EntityPersister entityDescriptor = resolveEntityPersister ( sqmJoin .getReferencedPathSource () );
3446
3444
3447
3445
final SqlAstJoinType correspondingSqlJoinType = sqmJoin .getSqmJoinType ().getCorrespondingSqlJoinType ();
@@ -3450,12 +3448,12 @@ private TableGroup consumeEntityJoin(SqmEntityJoin<?> sqmJoin, TableGroup lhsTab
3450
3448
sqmJoin .getNavigablePath (),
3451
3449
sqmJoin .getExplicitAlias (),
3452
3450
null ,
3453
- () -> p -> needsTreat . setValue ( true ) ,
3451
+ () -> p -> {} ,
3454
3452
this
3455
3453
);
3456
3454
registerSqmFromTableGroup ( sqmJoin , tableGroup );
3457
3455
3458
- if ( needsTreat . getValue () ) {
3456
+ if ( entityDescriptor . isInherited () && ! sqmJoin . hasTreats () ) {
3459
3457
// Register new treat to apply the discriminator condition to the table reference itself, see #pruneTableGroupJoins
3460
3458
registerEntityNameUsage ( tableGroup , EntityNameUse .TREAT , entityDescriptor .getEntityName () );
3461
3459
}
@@ -3479,8 +3477,8 @@ private TableGroup consumeEntityJoin(SqmEntityJoin<?> sqmJoin, TableGroup lhsTab
3479
3477
3480
3478
final SoftDeleteMapping softDeleteMapping = entityDescriptor .getSoftDeleteMapping ();
3481
3479
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 () ),
3484
3482
softDeleteMapping
3485
3483
);
3486
3484
tableGroupJoin .applyPredicate ( softDeleteRestriction );
0 commit comments