From ed743a590d54c14567306b35409690c839ff8296 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 17 Nov 2023 16:02:35 +0100 Subject: [PATCH] HHH-16967 Missing join on inheritance parent table to validate @Where condition --- .../persister/entity/AbstractEntityPersister.java | 4 ++++ .../persister/entity/JoinedSubclassEntityPersister.java | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 8f626ca775..40ff18a7d4 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -6718,4 +6718,8 @@ public abstract class AbstractEntityPersister public String getDiscriminatorAlias() { return DISCRIMINATOR_ALIAS; } + + protected String getSqlWhereStringTableExpression(){ + return sqlWhereStringTableExpression; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java index 6ce853182a..2dc8bd8ba1 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/JoinedSubclassEntityPersister.java @@ -1366,6 +1366,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister { if ( mainTableReference != null ) { retainedTableReferences.add( mainTableReference ); } + final String sqlWhereStringTableExpression = persister.getSqlWhereStringTableExpression(); + if ( sqlWhereStringTableExpression != null ) { + final TableReference tableReference = tableGroup.getTableReference( sqlWhereStringTableExpression ); + if ( tableReference != null ) { + retainedTableReferences.add( tableReference ); + } + } if ( needsDiscriminator() ) { // We allow multiple joined subclasses to use the same table if they define a discriminator column. // In this case, we might need to add a discriminator condition to make sure we filter the correct subtype,