mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-27 14:30:16 +00:00
HHH-17638 Prevent reusing left joins for implicitly joined paths
This commit is contained in:
parent
86dad3d702
commit
18d88a4430
@ -3647,7 +3647,10 @@ private <X> X prepareReusablePath(
|
||||
if ( sqmPath instanceof SqmEntityValuedSimplePath<?>
|
||||
|| sqmPath instanceof SqmEmbeddedValuedSimplePath<?>
|
||||
|| sqmPath instanceof SqmAnyValuedSimplePath<?> ) {
|
||||
final TableGroup existingTableGroup = fromClauseIndex.findTableGroupForGetOrCreate( sqmPath.getNavigablePath() );
|
||||
final TableGroup existingTableGroup = fromClauseIndex.findTableGroupForGetOrCreate(
|
||||
sqmPath.getNavigablePath(),
|
||||
allowLeftJoins
|
||||
);
|
||||
if ( existingTableGroup == null ) {
|
||||
final TableGroup createdTableGroup = createTableGroup(
|
||||
getActualTableGroup(
|
||||
@ -3900,9 +3903,9 @@ private TableGroup createTableGroup(TableGroup parentTableGroup, SqmPath<?> join
|
||||
private boolean isMappedByOrNotFoundToOne(TableGroupJoinProducer joinProducer) {
|
||||
if ( joinProducer instanceof ToOneAttributeMapping ) {
|
||||
final ToOneAttributeMapping toOne = (ToOneAttributeMapping) joinProducer;
|
||||
if ( toOne.hasNotFoundAction() || toOne.getReferencedPropertyName() != null ) {
|
||||
return true;
|
||||
}
|
||||
return toOne.hasNotFoundAction() ||
|
||||
// ToOne( mappedBy = "..." ) always has a referenced property name and is the target side
|
||||
( toOne.getReferencedPropertyName() != null && toOne.getSideNature() == ForeignKeyDescriptor.Nature.TARGET );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -9,11 +9,14 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.SqlTreeCreationLogger;
|
||||
import org.hibernate.sql.ast.tree.from.CorrelatedTableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroupJoin;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@ -83,6 +86,17 @@ public TableGroup findTableGroupForGetOrCreate(NavigablePath navigablePath) {
|
||||
}
|
||||
}
|
||||
|
||||
public TableGroup findTableGroupForGetOrCreate(NavigablePath navigablePath, boolean allowLeftJoins) {
|
||||
final TableGroup tableGroup = findTableGroupForGetOrCreate( navigablePath );
|
||||
if ( !allowLeftJoins && tableGroup != null && navigablePath.getParent() != null
|
||||
&& CollectionPart.Nature.fromNameExact( navigablePath.getLocalName() ) == null ) {
|
||||
// This is an implicitly joined path, do not reuse existing table group if it's left joined
|
||||
final TableGroupJoin join = findTableGroup( navigablePath.getParent() ).findTableGroupJoin( tableGroup );
|
||||
return join != null && join.getJoinType() == SqlAstJoinType.LEFT ? null : tableGroup;
|
||||
}
|
||||
return tableGroup;
|
||||
}
|
||||
|
||||
private TableGroup getCorrelatedTableGroup(TableGroup tableGroup) {
|
||||
if ( tableGroup instanceof CorrelatedTableGroup ) {
|
||||
return getCorrelatedTableGroup( ( (CorrelatedTableGroup) tableGroup ).getCorrelatedTableGroup() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user