diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index 27f16af5bb..f3f1d092bb 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -3386,6 +3386,11 @@ public class ModelBinder { } protected void bindCollectionElement() { + log.debugf( + "Binding [%s] element type for a [%s]", + getPluralAttributeSource().getElementSource().getNature(), + getPluralAttributeSource().getNature() + ); if ( getPluralAttributeSource().getElementSource() instanceof PluralAttributeElementSourceBasic ) { final PluralAttributeElementSourceBasic elementSource = (PluralAttributeElementSourceBasic) getPluralAttributeSource().getElementSource(); @@ -3414,6 +3419,10 @@ public class ModelBinder { ); getCollectionBinding().setElement( elementBinding ); + // Collection#setWhere is used to set the "where" clause that applies to the collection table + // (the table containing the basic elements) + // This "where" clause comes from the collection mapping; e.g., + getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() ); } else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttributeElementSourceEmbedded ) { final PluralAttributeElementSourceEmbedded elementSource = @@ -3435,6 +3444,10 @@ public class ModelBinder { ); getCollectionBinding().setElement( elementBinding ); + // Collection#setWhere is used to set the "where" clause that applies to the collection table + // (the table containing the embeddable elements) + // This "where" clause comes from the collection mapping; e.g., + getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() ); } else if ( getPluralAttributeSource().getElementSource() instanceof PluralAttributeElementSourceOneToMany ) { final PluralAttributeElementSourceOneToMany elementSource = @@ -3603,6 +3616,11 @@ public class ModelBinder { ); getCollectionBinding().setElement( elementBinding ); + // Collection#setWhere is used to set the "where" clause that applies to the collection table + // (which is the join table for a many-to-any association). + // This "where" clause comes from the collection mapping; e.g., + getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() ); + getCollectionBinding().setWhere( getPluralAttributeSource().getWhere() ); } } }