HHH-15902 @OneToMany relationship with @Where on child table generates wrong sql
This commit is contained in:
parent
3765837b9e
commit
7b308d048f
|
@ -48,7 +48,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||
* List<Document> documents;
|
||||
* </pre>
|
||||
* <p>
|
||||
* By default, {@code @Where} restrictions declared for an entity are not
|
||||
* By default, {@code @Where} restrictions declared for an entity are
|
||||
* applied when loading a collection of that entity type. This behavior is
|
||||
* controlled by:
|
||||
* <ol>
|
||||
|
@ -84,7 +84,7 @@ public @interface Where {
|
|||
* <p>
|
||||
* By default, the restriction is not applied unless the property
|
||||
* {@value org.hibernate.cfg.AvailableSettings#USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS}
|
||||
* is explicitly enabled.
|
||||
* is explicitly disabled.
|
||||
*
|
||||
* @return {@code true} if the restriction should be applied even
|
||||
* if the configuration property is not enabled
|
||||
|
|
|
@ -2041,8 +2041,8 @@ public interface AvailableSettings {
|
|||
* {@link jakarta.persistence.ManyToMany many-to-many} association whose target
|
||||
* type defines the restriction.
|
||||
* <p>
|
||||
* By default, the restriction is not applied. When this setting is enabled, the
|
||||
* restriction is applied.
|
||||
* By default, the restriction is applied. When this setting is disabled, the
|
||||
* restriction is not applied.
|
||||
* <p>
|
||||
* The setting has no effect on a collection of {@link jakarta.persistence.Embeddable
|
||||
* embeddable} values containing a {@link jakarta.persistence.ManyToOne many-to-one}
|
||||
|
|
|
@ -576,6 +576,8 @@ public class LoaderSelectBuilder {
|
|||
TableGroup tableGroup,
|
||||
PluralAttributeMapping pluralAttributeMapping,
|
||||
SqlAstCreationState astCreationState) {
|
||||
final NavigablePath parentNavigablePath = tableGroup.getNavigablePath().getParent();
|
||||
if ( parentNavigablePath == null ) {
|
||||
pluralAttributeMapping.applyBaseRestrictions(
|
||||
querySpec::applyPredicate,
|
||||
tableGroup,
|
||||
|
@ -584,15 +586,18 @@ public class LoaderSelectBuilder {
|
|||
null,
|
||||
astCreationState
|
||||
);
|
||||
|
||||
pluralAttributeMapping.applyBaseManyToManyRestrictions(
|
||||
(filterPredicate) -> {
|
||||
final NavigablePath parentNavigablePath = tableGroup.getNavigablePath().getParent();
|
||||
if ( parentNavigablePath == null ) {
|
||||
querySpec.applyPredicate( filterPredicate );
|
||||
querySpec::applyPredicate,
|
||||
tableGroup,
|
||||
true,
|
||||
loadQueryInfluencers.getEnabledFilters(),
|
||||
null,
|
||||
astCreationState
|
||||
);
|
||||
}
|
||||
else {
|
||||
final TableGroup parentTableGroup = astCreationState.getFromClauseAccess().getTableGroup( parentNavigablePath );
|
||||
final TableGroup parentTableGroup = astCreationState.getFromClauseAccess().getTableGroup(
|
||||
parentNavigablePath );
|
||||
TableGroupJoin pluralTableGroupJoin = null;
|
||||
for ( TableGroupJoin nestedTableGroupJoin : parentTableGroup.getTableGroupJoins() ) {
|
||||
if ( nestedTableGroupJoin.getNavigablePath() == tableGroup.getNavigablePath() ) {
|
||||
|
@ -602,15 +607,24 @@ public class LoaderSelectBuilder {
|
|||
}
|
||||
|
||||
assert pluralTableGroupJoin != null;
|
||||
pluralTableGroupJoin.applyPredicate( filterPredicate );
|
||||
}
|
||||
},
|
||||
|
||||
pluralAttributeMapping.applyBaseRestrictions(
|
||||
pluralTableGroupJoin::applyPredicate,
|
||||
tableGroup,
|
||||
true,
|
||||
loadQueryInfluencers.getEnabledFilters(),
|
||||
null,
|
||||
astCreationState
|
||||
);
|
||||
pluralAttributeMapping.applyBaseManyToManyRestrictions(
|
||||
pluralTableGroupJoin::applyPredicate,
|
||||
tableGroup,
|
||||
true,
|
||||
loadQueryInfluencers.getEnabledFilters(),
|
||||
null,
|
||||
astCreationState
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyFiltering(
|
||||
|
|
Loading…
Reference in New Issue