HHH-15674 @NamedEntityGraph not working on entity that have composite PK
This commit is contained in:
parent
ff28d677ab
commit
23cff8bd10
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.sql.results.graph;
|
||||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
|
@ -39,4 +40,9 @@ public interface DomainResultGraphNode {
|
|||
// override this already to return it
|
||||
return null;
|
||||
}
|
||||
|
||||
default boolean appliesTo(GraphImplementor graphImplementor){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.sql.results.graph.embeddable.internal;
|
||||
|
||||
import org.hibernate.engine.FetchTiming;
|
||||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
|
||||
import org.hibernate.metamodel.mapping.EmbeddableMappingType;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
|
@ -30,7 +31,6 @@ import org.hibernate.sql.results.graph.embeddable.EmbeddableValuedFetchable;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class EmbeddableFetchImpl extends AbstractFetchParent implements EmbeddableResultGraphNode, Fetch {
|
||||
private final EmbeddableValuedFetchable embeddedPartDescriptor;
|
||||
|
||||
private final FetchParent fetchParent;
|
||||
private final FetchTiming fetchTiming;
|
||||
|
@ -45,7 +45,6 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
|
|||
boolean hasTableGroup,
|
||||
DomainResultCreationState creationState) {
|
||||
super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath );
|
||||
this.embeddedPartDescriptor = embeddedPartDescriptor;
|
||||
|
||||
this.fetchParent = fetchParent;
|
||||
this.fetchTiming = fetchTiming;
|
||||
|
@ -142,4 +141,10 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
|
|||
|
||||
return new EmbeddableAssembler( initializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(GraphImplementor graphImplementor) {
|
||||
return getFetchParent().appliesTo( graphImplementor );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
package org.hibernate.sql.results.graph.entity;
|
||||
|
||||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.sql.results.graph.DomainResultGraphNode;
|
||||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
|
@ -38,4 +39,11 @@ public interface EntityResultGraphNode extends DomainResultGraphNode, FetchParen
|
|||
default EntityMappingType getReferencedMappingContainer() {
|
||||
return getEntityValuedModelPart().getEntityMappingType();
|
||||
}
|
||||
|
||||
@Override
|
||||
default boolean appliesTo(GraphImplementor graphImplementor) {
|
||||
return graphImplementor.appliesTo(
|
||||
getEntityValuedModelPart().getEntityMappingType().getJavaType().getJavaTypeClass()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,11 @@ import org.hibernate.graph.spi.GraphImplementor;
|
|||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.mapping.CollectionPart;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.EntityCollectionPart;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.sql.results.graph.EntityGraphTraversalState;
|
||||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.sql.results.graph.Fetchable;
|
||||
import org.hibernate.sql.results.graph.entity.EntityResultGraphNode;
|
||||
|
||||
import jakarta.persistence.metamodel.PluralAttribute;
|
||||
|
||||
|
@ -117,17 +114,10 @@ public class StandardEntityGraphTraversalStateImpl implements EntityGraphTravers
|
|||
}
|
||||
|
||||
private boolean appliesTo(FetchParent fetchParent) {
|
||||
if ( currentGraphContext == null || !( fetchParent instanceof EntityResultGraphNode ) ) {
|
||||
if ( currentGraphContext == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final EntityResultGraphNode entityFetchParent = (EntityResultGraphNode) fetchParent;
|
||||
final EntityMappingType entityFetchParentMappingType = entityFetchParent.getEntityValuedModelPart().getEntityMappingType();
|
||||
|
||||
assert currentGraphContext.getGraphedType() instanceof EntityDomainType;
|
||||
final EntityDomainType entityDomainType = (EntityDomainType) currentGraphContext.getGraphedType();
|
||||
|
||||
return entityDomainType.getHibernateEntityName().equals( entityFetchParentMappingType.getEntityName() );
|
||||
return fetchParent.appliesTo( currentGraphContext );
|
||||
}
|
||||
|
||||
private static boolean isJpaMapCollectionType(PluralAttributeMapping pluralAttributeMapping) {
|
||||
|
|
Loading…
Reference in New Issue