HHH-16885 Hibernate 6.x changes outer to inner join when @EntityGraph and @Id

This commit is contained in:
Andrea Boriero 2023-09-27 14:35:53 +02:00 committed by Andrea Boriero
parent f808546570
commit 383653d5d4
4 changed files with 20 additions and 42 deletions

View File

@ -126,13 +126,7 @@ public abstract class AbstractCompositeIdentifierMapping
boolean fetched, boolean fetched,
boolean addsPredicate, boolean addsPredicate,
SqlAstCreationState creationState) { SqlAstCreationState creationState) {
final SqlAstJoinType joinType; final SqlAstJoinType joinType = determineSqlJoinType( lhs, requestedJoinType, fetched );
if ( requestedJoinType == null ) {
joinType = SqlAstJoinType.INNER;
}
else {
joinType = requestedJoinType;
}
final TableGroup tableGroup = createRootTableGroupJoin( final TableGroup tableGroup = createRootTableGroupJoin(
navigablePath, navigablePath,
lhs, lhs,
@ -295,4 +289,5 @@ public abstract class AbstractCompositeIdentifierMapping
public boolean containsTableReference(String tableExpression) { public boolean containsTableReference(String tableExpression) {
return entityMapping.containsTableReference( tableExpression ); return entityMapping.containsTableReference( tableExpression );
} }
} }

View File

@ -680,22 +680,6 @@ public class PluralAttributeMappingImpl
); );
} }
private SqlAstJoinType determineSqlJoinType(TableGroup lhs, SqlAstJoinType requestedJoinType, boolean fetched) {
final SqlAstJoinType joinType;
if ( requestedJoinType == null ) {
if ( fetched ) {
joinType = getDefaultSqlAstJoinType( lhs );
}
else {
joinType = SqlAstJoinType.INNER;
}
}
else {
joinType = requestedJoinType;
}
return joinType;
}
@Override @Override
public TableGroup createRootTableGroupJoin( public TableGroup createRootTableGroupJoin(
NavigablePath navigablePath, NavigablePath navigablePath,
@ -707,9 +691,7 @@ public class PluralAttributeMappingImpl
Consumer<Predicate> predicateConsumer, Consumer<Predicate> predicateConsumer,
SqlAstCreationState creationState) { SqlAstCreationState creationState) {
final CollectionPersister collectionDescriptor = getCollectionDescriptor(); final CollectionPersister collectionDescriptor = getCollectionDescriptor();
final SqlAstJoinType joinType = requestedJoinType == null final SqlAstJoinType joinType = determineSqlJoinType( lhs, requestedJoinType, fetched );
? SqlAstJoinType.INNER
: requestedJoinType;
final SqlAliasBase sqlAliasBase = creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() ); final SqlAliasBase sqlAliasBase = creationState.getSqlAliasBaseGenerator().createSqlAliasBase( getSqlAliasStem() );
final TableGroup tableGroup; final TableGroup tableGroup;
@ -741,6 +723,7 @@ public class PluralAttributeMappingImpl
return tableGroup; return tableGroup;
} }
@Override @Override
public void setForeignKeyDescriptor(ForeignKeyDescriptor fkDescriptor) { public void setForeignKeyDescriptor(ForeignKeyDescriptor fkDescriptor) {
this.fkDescriptor = fkDescriptor; this.fkDescriptor = fkDescriptor;

View File

@ -1991,22 +1991,6 @@ public class ToOneAttributeMapping
return join; return join;
} }
private SqlAstJoinType determineSqlJoinType(TableGroup lhs, SqlAstJoinType requestedJoinType, boolean fetched) {
final SqlAstJoinType joinType;
if ( requestedJoinType == null ) {
if ( fetched ) {
joinType = getDefaultSqlAstJoinType( lhs );
}
else {
joinType = SqlAstJoinType.INNER;
}
}
else {
joinType = requestedJoinType;
}
return joinType;
}
@Override @Override
public LazyTableGroup createRootTableGroupJoin( public LazyTableGroup createRootTableGroupJoin(
NavigablePath navigablePath, NavigablePath navigablePath,

View File

@ -76,4 +76,20 @@ public interface TableGroupJoinProducer extends TableGroupProducer {
boolean fetched, boolean fetched,
Consumer<Predicate> predicateConsumer, Consumer<Predicate> predicateConsumer,
SqlAstCreationState creationState); SqlAstCreationState creationState);
default SqlAstJoinType determineSqlJoinType(TableGroup lhs, SqlAstJoinType requestedJoinType, boolean fetched) {
final SqlAstJoinType joinType;
if ( requestedJoinType == null ) {
if ( fetched ) {
joinType = getDefaultSqlAstJoinType( lhs );
}
else {
joinType = SqlAstJoinType.INNER;
}
}
else {
joinType = requestedJoinType;
}
return joinType;
}
} }