HHH-16988 Fix and simplify the getNavigablePathCopy method
Handle implicitly treated navigable paths copy correctly. Also, small change to findPluralAttribute() to correctly handle multiple inheritance types.
This commit is contained in:
parent
cfc7b3104f
commit
ada4701a95
|
@ -441,7 +441,7 @@ public abstract class AbstractManagedType<J>
|
|||
return attribute;
|
||||
}
|
||||
else if ( getSuperType() != null ) {
|
||||
return getSuperType().findDeclaredPluralAttribute( name );
|
||||
return getSuperType().findPluralAttribute( name );
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.query.sqm.tree.expression.SqmExpression;
|
|||
import org.hibernate.query.sqm.tree.expression.SqmLiteral;
|
||||
import org.hibernate.spi.EntityIdentifierNavigablePath;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.spi.TreatedNavigablePath;
|
||||
|
||||
import jakarta.persistence.metamodel.MapAttribute;
|
||||
import jakarta.persistence.metamodel.PluralAttribute;
|
||||
|
@ -227,37 +228,45 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
|
|||
* and if not creates a copy of the navigable path with the correct parent.
|
||||
*/
|
||||
protected NavigablePath getNavigablePathCopy(SqmPath<?> parent) {
|
||||
return getNavigablePathCopy( castNonNull( navigablePath.getRealParent() ), parent.getNavigablePath(), false, null );
|
||||
final NavigablePath realParentPath = getRealParentPath(
|
||||
castNonNull( navigablePath.getRealParent() ),
|
||||
parent.getNavigablePath()
|
||||
);
|
||||
if ( realParentPath != null ) {
|
||||
return realParentPath.append( navigablePath.getLocalName(), navigablePath.getAlias() );
|
||||
}
|
||||
return navigablePath;
|
||||
}
|
||||
|
||||
private NavigablePath getNavigablePathCopy(
|
||||
NavigablePath realParent,
|
||||
NavigablePath parent,
|
||||
boolean isId,
|
||||
String identifierAttributeName) {
|
||||
private NavigablePath getRealParentPath(NavigablePath realParent, NavigablePath parent) {
|
||||
if ( parent == realParent ) {
|
||||
return navigablePath;
|
||||
return null;
|
||||
}
|
||||
else if ( !isId && realParent instanceof EntityIdentifierNavigablePath ) {
|
||||
return getNavigablePathCopy(
|
||||
castNonNull( realParent.getRealParent() ),
|
||||
parent,
|
||||
true,
|
||||
( (EntityIdentifierNavigablePath) realParent ).getIdentifierAttributeName()
|
||||
);
|
||||
else if ( realParent instanceof EntityIdentifierNavigablePath ) {
|
||||
parent = getRealParentPath( castNonNull( realParent.getRealParent() ), parent );
|
||||
if ( parent != null ) {
|
||||
parent = new EntityIdentifierNavigablePath(
|
||||
parent,
|
||||
( (EntityIdentifierNavigablePath) realParent ).getIdentifierAttributeName()
|
||||
);
|
||||
}
|
||||
}
|
||||
else if ( realParent.getAlias() == null && realParent instanceof TreatedNavigablePath ) {
|
||||
// This might be an implicitly treated parent path, check with the non-treated parent
|
||||
parent = getRealParentPath( castNonNull( realParent.getRealParent() ), parent );
|
||||
if ( parent != null ) {
|
||||
parent = parent.treatAs( realParent.getLocalName().substring( 1 ) );
|
||||
}
|
||||
}
|
||||
else if ( CollectionPart.Nature.fromNameExact( realParent.getLocalName() ) != null ) {
|
||||
if ( parent == realParent.getRealParent() ) {
|
||||
return navigablePath;
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
parent = parent.append( realParent.getLocalName() );
|
||||
}
|
||||
}
|
||||
if ( isId ) {
|
||||
parent = new EntityIdentifierNavigablePath( parent, identifierAttributeName );
|
||||
}
|
||||
return parent.append( navigablePath.getLocalName(), navigablePath.getAlias() );
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue