From b18c967cf60b492a4f8f651f58dc42daf6c34db0 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 31 Aug 2022 17:16:44 +0200 Subject: [PATCH] HHH-13485 FilterJoinTable does not to use the defualt condition --- .../cfg/annotations/CollectionBinder.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java index 115aac52d6..8c0c877703 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/CollectionBinder.java @@ -103,6 +103,7 @@ import org.hibernate.cfg.PropertyInferredData; import org.hibernate.cfg.PropertyPreloadedData; import org.hibernate.cfg.SecondPass; import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; @@ -1364,10 +1365,25 @@ public abstract class CollectionBinder { } private void addFilter(boolean hasAssociationTable, FilterJoinTable filter) { - if (hasAssociationTable) { + if ( hasAssociationTable ) { + final String condition; + if ( StringHelper.isEmpty( filter.condition() ) ) { + final FilterDefinition filterDefinition = buildingContext.getMetadataCollector() + .getFilterDefinition( filter.name() ); + if ( filterDefinition == null ) { + throw new AnnotationException( + "@FilterJoinTable on an association without condition attribute and without an any @FilterDef with a default condition" + + StringHelper.qualify( propertyHolder.getPath(), propertyName ) + ); + } + condition = filterDefinition.getDefaultFilterCondition(); + } + else { + condition = filter.condition(); + } collection.addFilter( filter.name(), - filter.condition(), + condition, filter.deduceAliasInjectionPoints(), toAliasTableMap( filter.aliases() ), toAliasEntityMap( filter.aliases() )