HHH-18138 entity graphs must respect concrete generic attribute

Co-authored-by: Marco Belladelli <marcobladel@gmail.com>
This commit is contained in:
Matej Pucihar 2024-05-25 00:20:37 +02:00 committed by Marco Belladelli
parent 7ef0680601
commit 81d700c382
2 changed files with 12 additions and 2 deletions

View File

@ -23,6 +23,7 @@ import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.query.sqm.SqmPathSource;
import static java.util.Collections.emptyList;
@ -123,7 +124,10 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
@Override
@SuppressWarnings("unchecked")
public <AJ> AttributeNodeImplementor<AJ> findAttributeNode(String attributeName) {
final PersistentAttribute<? super J, ?> attribute = managedType.findAttributeInSuperTypes( attributeName );
PersistentAttribute<? super J, ?> attribute = managedType.findAttributeInSuperTypes( attributeName );
if ( attribute instanceof SqmPathSource && ( (SqmPathSource<?>) attribute ).isGeneric() ) {
attribute = managedType.findConcreteGenericAttribute( attributeName );
}
return attribute == null ? null : findAttributeNode( (PersistentAttribute<? extends J, AJ>) attribute );
}

View File

@ -14,6 +14,7 @@ import org.hibernate.graph.CannotBecomeEntityGraphException;
import org.hibernate.graph.CannotContainSubGraphException;
import org.hibernate.graph.Graph;
import org.hibernate.metamodel.model.domain.PersistentAttribute;
import org.hibernate.query.sqm.SqmPathSource;
/**
* Integration version of the {@link Graph} contract
@ -74,7 +75,12 @@ public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
@SuppressWarnings("unchecked")
default <AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(String name) {
return findOrCreateAttributeNode( (PersistentAttribute<? extends J,AJ>) getGraphedType().getAttribute( name ) );
PersistentAttribute<? super J, ?> attribute = getGraphedType().getAttribute( name );
if ( attribute instanceof SqmPathSource && ( (SqmPathSource<?>) attribute ).isGeneric() ) {
attribute = getGraphedType().findConcreteGenericAttribute( name );
}
return findOrCreateAttributeNode( (PersistentAttribute<? extends J, AJ>) attribute );
}
<AJ> AttributeNodeImplementor<AJ> findOrCreateAttributeNode(PersistentAttribute<? extends J, AJ> attribute);