From 0721629a1919fe9fda6fa7caceef16d7207ce43a Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Fri, 22 Dec 2023 23:07:05 +0100 Subject: [PATCH] HHH-17511 - Fix for missing condition in join with a @SoftDelete marked Entity Signed-off-by: Jan Schatteman --- .../sqm/sql/BaseSqmToSqlAstConverter.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index bb908e81a9..aca56bf3ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -12,6 +12,7 @@ import jakarta.persistence.metamodel.Type; import org.hibernate.HibernateException; import org.hibernate.Internal; import org.hibernate.LockMode; +import org.hibernate.boot.model.internal.SoftDeleteHelper; import org.hibernate.boot.model.process.internal.InferredBasicValueResolver; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.TimestampaddFunction; @@ -64,6 +65,7 @@ import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.mapping.Restrictable; import org.hibernate.metamodel.mapping.SelectableMapping; import org.hibernate.metamodel.mapping.SelectableMappings; +import org.hibernate.metamodel.mapping.SoftDeleteMapping; import org.hibernate.metamodel.mapping.SqlExpressible; import org.hibernate.metamodel.mapping.SqlTypedMapping; import org.hibernate.metamodel.mapping.ValueMapping; @@ -3472,6 +3474,24 @@ public abstract class BaseSqmToSqlAstConverter extends Base ); lhsTableGroup.addTableGroupJoin( tableGroupJoin ); + entityDescriptor.applyBaseRestrictions( + tableGroupJoin::applyPredicate, + tableGroup, + true, + getLoadQueryInfluencers().getEnabledFilters(), + null, + this + ); + + final SoftDeleteMapping softDeleteMapping = entityDescriptor.getSoftDeleteMapping(); + if ( softDeleteMapping != null ) { + final Predicate softDeleteRestriction = SoftDeleteHelper.createNonSoftDeletedRestriction( + tableGroup.resolveTableReference( entityDescriptor.getSoftDeleteTableDetails().getTableName() ), + softDeleteMapping + ); + tableGroupJoin.applyPredicate( softDeleteRestriction ); + } + if ( sqmJoin.getJoinPredicate() != null ) { final SqmJoin oldJoin = currentlyProcessingJoin; currentlyProcessingJoin = sqmJoin;