detach EntityGraphs from the JpaMetamodel
so that they can be newed more easily
This commit is contained in:
parent
1e05e8444e
commit
d32e8adaf2
|
@ -21,7 +21,6 @@ import org.hibernate.graph.spi.AttributeNodeImplementor;
|
|||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.graph.spi.RootGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
|
||||
|
@ -36,17 +35,13 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
private final ManagedDomainType<J> managedType;
|
||||
private Map<PersistentAttribute<?,?>, AttributeNodeImplementor<?>> attrNodeMap;
|
||||
|
||||
public AbstractGraph(
|
||||
ManagedDomainType<J> managedType,
|
||||
boolean mutable,
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super( mutable, jpaMetamodel );
|
||||
public AbstractGraph(ManagedDomainType<J> managedType, boolean mutable) {
|
||||
super( mutable );
|
||||
this.managedType = managedType;
|
||||
}
|
||||
|
||||
protected AbstractGraph(boolean mutable, GraphImplementor<J> original) {
|
||||
this( original.getGraphedType(), mutable, original.jpaMetamodel() );
|
||||
|
||||
protected AbstractGraph(GraphImplementor<J> original, boolean mutable) {
|
||||
this( original.getGraphedType(), mutable );
|
||||
this.attrNodeMap = new ConcurrentHashMap<>( original.getAttributeNodeList().size() );
|
||||
original.visitAttributeNodes(
|
||||
node -> attrNodeMap.put(
|
||||
|
@ -56,11 +51,6 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JpaMetamodel jpaMetamodel() {
|
||||
return super.jpaMetamodel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManagedDomainType<J> getGraphedType() {
|
||||
return managedType;
|
||||
|
@ -69,7 +59,7 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
@Override
|
||||
public RootGraphImplementor<J> makeRootGraph(String name, boolean mutable) {
|
||||
if ( getGraphedType() instanceof EntityDomainType ) {
|
||||
return new RootGraphImpl<>( name, mutable, this );
|
||||
return new RootGraphImpl<>( name, this, mutable);
|
||||
}
|
||||
|
||||
throw new CannotBecomeEntityGraphException(
|
||||
|
@ -180,7 +170,7 @@ public abstract class AbstractGraph<J> extends AbstractGraphNode<J> implements G
|
|||
}
|
||||
|
||||
if ( attrNode == null ) {
|
||||
attrNode = new AttributeNodeImpl<>( isMutable(), attribute, jpaMetamodel() );
|
||||
attrNode = new AttributeNodeImpl<>(attribute, isMutable());
|
||||
attrNodeMap.put( attribute, attrNode );
|
||||
}
|
||||
|
||||
|
|
|
@ -7,24 +7,18 @@
|
|||
package org.hibernate.graph.internal;
|
||||
|
||||
import org.hibernate.graph.spi.GraphNodeImplementor;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public abstract class AbstractGraphNode<J> implements GraphNodeImplementor<J> {
|
||||
private final JpaMetamodel jpaMetamodel;
|
||||
|
||||
private final boolean mutable;
|
||||
|
||||
public AbstractGraphNode(boolean mutable, JpaMetamodel jpaMetamodel) {
|
||||
this.jpaMetamodel = jpaMetamodel;
|
||||
public AbstractGraphNode(boolean mutable) {
|
||||
this.mutable = mutable;
|
||||
}
|
||||
|
||||
protected JpaMetamodel jpaMetamodel() {
|
||||
return jpaMetamodel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMutable() {
|
||||
return mutable;
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.graph.spi.AttributeNodeImplementor;
|
|||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.graph.spi.SubGraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.DomainType;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
|
@ -39,23 +38,19 @@ public class AttributeNodeImpl<J>
|
|||
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> subGraphMap;
|
||||
private Map<Class<? extends J>, SubGraphImplementor<? extends J>> keySubGraphMap;
|
||||
|
||||
public <X> AttributeNodeImpl(
|
||||
boolean mutable,
|
||||
PersistentAttribute<X, J> attribute,
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
this( mutable, attribute, null, null, jpaMetamodel );
|
||||
public <X> AttributeNodeImpl(PersistentAttribute<X, J> attribute, boolean mutable) {
|
||||
this(attribute, null, null, mutable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Intended only for use from making a copy
|
||||
*/
|
||||
private AttributeNodeImpl(
|
||||
boolean mutable,
|
||||
PersistentAttribute<?, J> attribute,
|
||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> subGraphMap,
|
||||
Map<Class<? extends J>, SubGraphImplementor<? extends J>> keySubGraphMap,
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super( mutable, jpaMetamodel );
|
||||
boolean mutable) {
|
||||
super( mutable );
|
||||
this.attribute = attribute;
|
||||
this.subGraphMap = subGraphMap;
|
||||
this.keySubGraphMap = keySubGraphMap;
|
||||
|
@ -224,11 +219,7 @@ public class AttributeNodeImpl<J>
|
|||
@Override
|
||||
public AttributeNodeImplementor<J> makeCopy(boolean mutable) {
|
||||
return new AttributeNodeImpl<>(
|
||||
mutable,
|
||||
this.attribute,
|
||||
makeMapCopy( mutable, subGraphMap ),
|
||||
makeMapCopy( mutable, keySubGraphMap ),
|
||||
jpaMetamodel()
|
||||
this.attribute, makeMapCopy( mutable, subGraphMap ), makeMapCopy( mutable, keySubGraphMap ), mutable
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,23 +23,20 @@ import jakarta.persistence.EntityGraph;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>, RootGraphImplementor<J> {
|
||||
|
||||
private final String name;
|
||||
|
||||
public RootGraphImpl(
|
||||
String name,
|
||||
EntityDomainType<J> entityType,
|
||||
boolean mutable,
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super( entityType, mutable, jpaMetamodel );
|
||||
public RootGraphImpl(String name, EntityDomainType<J> entityType, boolean mutable) {
|
||||
super( entityType, mutable );
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public RootGraphImpl(String name, EntityDomainType<J> entityType, JpaMetamodel jpaMetamodel) {
|
||||
this( name, entityType, true, jpaMetamodel );
|
||||
public RootGraphImpl(String name, EntityDomainType<J> entityType) {
|
||||
this( name, entityType, true );
|
||||
}
|
||||
|
||||
public RootGraphImpl(String name, boolean mutable, GraphImplementor<J> original) {
|
||||
super( mutable, original );
|
||||
public RootGraphImpl(String name, GraphImplementor<J> original, boolean mutable) {
|
||||
super(original, mutable);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
@ -50,12 +47,12 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
|||
|
||||
@Override
|
||||
public RootGraphImplementor<J> makeCopy(boolean mutable) {
|
||||
return new RootGraphImpl<>( null, mutable, this );
|
||||
return new RootGraphImpl<>( null, this, mutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubGraphImplementor<J> makeSubGraph(boolean mutable) {
|
||||
return new SubGraphImpl<>( mutable, this );
|
||||
return new SubGraphImpl<>(this, mutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +66,7 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(EntityDomainType<?> entityType) {
|
||||
public boolean appliesTo(EntityDomainType<?> entityType, JpaMetamodel metamodel) {
|
||||
final ManagedDomainType<J> managedTypeDescriptor = getGraphedType();
|
||||
if ( managedTypeDescriptor.equals( entityType ) ) {
|
||||
return true;
|
||||
|
@ -87,12 +84,12 @@ public class RootGraphImpl<J> extends AbstractGraph<J> implements EntityGraph<J>
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(String entityName) {
|
||||
return appliesTo( jpaMetamodel().entity( entityName ) );
|
||||
public boolean appliesTo(String entityName, JpaMetamodel metamodel) {
|
||||
return appliesTo( metamodel.entity( entityName ), metamodel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(Class<?> type) {
|
||||
return appliesTo( jpaMetamodel().entity( type ) );
|
||||
public boolean appliesTo(Class<?> type, JpaMetamodel metamodel) {
|
||||
return appliesTo( metamodel.entity( type ), metamodel );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,29 +14,23 @@ import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImplementor<J> {
|
||||
public SubGraphImpl(
|
||||
ManagedDomainType<J> managedType,
|
||||
boolean mutable,
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super( managedType, mutable, jpaMetamodel );
|
||||
|
||||
public SubGraphImpl(ManagedDomainType<J> managedType, boolean mutable) {
|
||||
super( managedType, mutable );
|
||||
}
|
||||
|
||||
public SubGraphImpl(boolean mutable, AbstractGraph<J> original) {
|
||||
super( mutable, original );
|
||||
public SubGraphImpl(AbstractGraph<J> original, boolean mutable) {
|
||||
super(original, mutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubGraphImplementor<J> makeCopy(boolean mutable) {
|
||||
return new SubGraphImpl<>( mutable, this );
|
||||
return new SubGraphImpl<>(this, mutable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SubGraphImplementor<J> makeSubGraph(boolean mutable) {
|
||||
if ( ! mutable && ! isMutable() ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return makeCopy( true );
|
||||
return !mutable && !isMutable() ? this : makeCopy( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +39,7 @@ public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImpleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(ManagedDomainType<?> managedType) {
|
||||
public boolean appliesTo(ManagedDomainType<?> managedType, JpaMetamodel metamodel) {
|
||||
if ( getGraphedType().equals( managedType ) ) {
|
||||
return true;
|
||||
}
|
||||
|
@ -62,7 +56,7 @@ public class SubGraphImpl<J> extends AbstractGraph<J> implements SubGraphImpleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(Class<?> javaType) {
|
||||
return appliesTo( jpaMetamodel().managedType( javaType ) );
|
||||
public boolean appliesTo(Class<?> javaType, JpaMetamodel metamodel) {
|
||||
return appliesTo( metamodel.managedType( javaType ), metamodel );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ import org.hibernate.internal.util.StringHelper;
|
|||
import org.hibernate.internal.util.collections.Stack;
|
||||
import org.hibernate.internal.util.collections.StandardStack;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
|
||||
|
|
|
@ -26,14 +26,12 @@ import org.hibernate.metamodel.model.domain.PersistentAttribute;
|
|||
*/
|
||||
public interface GraphImplementor<J> extends Graph<J>, GraphNodeImplementor<J> {
|
||||
|
||||
boolean appliesTo(ManagedDomainType<?> managedType);
|
||||
boolean appliesTo(ManagedDomainType<?> managedType, JpaMetamodel metamodel);
|
||||
|
||||
boolean appliesTo(Class<?> javaType);
|
||||
boolean appliesTo(Class<?> javaType, JpaMetamodel metamodel);
|
||||
|
||||
void merge(GraphImplementor<? extends J> other);
|
||||
|
||||
JpaMetamodel jpaMetamodel();
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Co-variant returns
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.graph.spi;
|
|||
|
||||
import org.hibernate.graph.RootGraph;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
|
||||
/**
|
||||
|
@ -17,14 +18,14 @@ import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
|||
*/
|
||||
public interface RootGraphImplementor<J> extends RootGraph<J>, GraphImplementor<J> {
|
||||
|
||||
boolean appliesTo(String entityName);
|
||||
boolean appliesTo(String entityName, JpaMetamodel metamodel);
|
||||
|
||||
boolean appliesTo(EntityDomainType<?> entityType);
|
||||
boolean appliesTo(EntityDomainType<?> entityType, JpaMetamodel metamodel);
|
||||
|
||||
@Override
|
||||
default boolean appliesTo(ManagedDomainType<?> managedType) {
|
||||
default boolean appliesTo(ManagedDomainType<?> managedType, JpaMetamodel metamodel) {
|
||||
assert managedType instanceof EntityDomainType;
|
||||
return appliesTo( (EntityDomainType<?>) managedType );
|
||||
return appliesTo( (EntityDomainType<?>) managedType, metamodel );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1064,7 +1064,7 @@ public class SessionImpl
|
|||
final GraphSemantic semantic = effectiveEntityGraph.getSemantic();
|
||||
final RootGraphImplementor<?> graph = effectiveEntityGraph.getGraph();
|
||||
boolean clearedEffectiveGraph;
|
||||
if ( semantic == null || graph.appliesTo( entityName ) ) {
|
||||
if ( semantic == null || graph.appliesTo( entityName, getFactory().getJpaMetamodel() ) ) {
|
||||
clearedEffectiveGraph = false;
|
||||
}
|
||||
else {
|
||||
|
@ -2862,11 +2862,7 @@ public class SessionImpl
|
|||
@Override
|
||||
public <T> RootGraphImplementor<T> createEntityGraph(Class<T> rootType) {
|
||||
checkOpen();
|
||||
return new RootGraphImpl<>(
|
||||
null,
|
||||
getFactory().getJpaMetamodel().entity( rootType ),
|
||||
getEntityManagerFactory().getJpaMetamodel()
|
||||
);
|
||||
return new RootGraphImpl<>( null, getFactory().getJpaMetamodel().entity( rootType ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -130,7 +130,7 @@ public class LoaderSelectBuilder {
|
|||
1,
|
||||
loadQueryInfluencers,
|
||||
lockOptions,
|
||||
determineGraphTraversalState( loadQueryInfluencers ),
|
||||
determineGraphTraversalState( loadQueryInfluencers, sessionFactory ),
|
||||
true,
|
||||
jdbcParameterConsumer
|
||||
);
|
||||
|
@ -157,7 +157,7 @@ public class LoaderSelectBuilder {
|
|||
-1,
|
||||
influencers,
|
||||
lockOptions,
|
||||
determineGraphTraversalState( influencers ),
|
||||
determineGraphTraversalState( influencers, sessionFactory ),
|
||||
true,
|
||||
null
|
||||
);
|
||||
|
@ -385,7 +385,7 @@ public class LoaderSelectBuilder {
|
|||
numberOfKeysToLoad,
|
||||
loadQueryInfluencers,
|
||||
lockOptions != null ? lockOptions : LockOptions.NONE,
|
||||
determineGraphTraversalState( loadQueryInfluencers ),
|
||||
determineGraphTraversalState( loadQueryInfluencers, creationContext.getSessionFactory() ),
|
||||
determineWhetherToForceIdSelection( numberOfKeysToLoad, restrictedParts ),
|
||||
jdbcParameterConsumer
|
||||
);
|
||||
|
@ -435,14 +435,20 @@ public class LoaderSelectBuilder {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static EntityGraphTraversalState determineGraphTraversalState(LoadQueryInfluencers loadQueryInfluencers) {
|
||||
private static EntityGraphTraversalState determineGraphTraversalState(
|
||||
LoadQueryInfluencers loadQueryInfluencers,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
if ( loadQueryInfluencers != null ) {
|
||||
final EffectiveEntityGraph effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph();
|
||||
if ( effectiveEntityGraph != null ) {
|
||||
final GraphSemantic graphSemantic = effectiveEntityGraph.getSemantic();
|
||||
final RootGraphImplementor<?> rootGraphImplementor = effectiveEntityGraph.getGraph();
|
||||
if ( graphSemantic != null && rootGraphImplementor != null ) {
|
||||
return new StandardEntityGraphTraversalStateImpl( graphSemantic, rootGraphImplementor );
|
||||
return new StandardEntityGraphTraversalStateImpl(
|
||||
graphSemantic,
|
||||
rootGraphImplementor,
|
||||
sessionFactory.getJpaMetamodel()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -684,7 +684,7 @@ public abstract class AbstractManagedType<J>
|
|||
|
||||
@Override
|
||||
public SubGraphImplementor<J> makeSubGraph() {
|
||||
return new SubGraphImpl<>( this, true, jpaMetamodel() );
|
||||
return new SubGraphImpl<>( this, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -44,6 +44,6 @@ public class EmbeddableTypeImpl<J>
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <S extends J> SubGraphImplementor<S> makeSubGraph(Class<S> subType) {
|
||||
return new SubGraphImpl( this, true, jpaMetamodel() );
|
||||
return new SubGraphImpl( this, true );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ public class EntityTypeImpl<J>
|
|||
);
|
||||
}
|
||||
|
||||
return new SubGraphImpl( this, true, jpaMetamodel() );
|
||||
return new SubGraphImpl( this, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -277,7 +277,7 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
|
|||
|
||||
//noinspection unchecked
|
||||
final RootGraphImplementor<T> egi = (RootGraphImplementor<T>) entityGraph;
|
||||
if ( egi.appliesTo( entityType ) ) {
|
||||
if ( egi.appliesTo( entityType, this ) ) {
|
||||
results.add( egi );
|
||||
}
|
||||
}
|
||||
|
@ -351,11 +351,7 @@ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable {
|
|||
);
|
||||
}
|
||||
|
||||
final RootGraphImpl<Object> entityGraph = new RootGraphImpl<>(
|
||||
definition.getRegisteredName(),
|
||||
entityType,
|
||||
this
|
||||
);
|
||||
final RootGraphImpl<Object> entityGraph = new RootGraphImpl<>( definition.getRegisteredName(), entityType );
|
||||
|
||||
final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
|
||||
|
||||
|
|
|
@ -130,7 +130,7 @@ public class MappedSuperclassTypeImpl<J> extends AbstractIdentifiableType<J> imp
|
|||
);
|
||||
}
|
||||
|
||||
return new SubGraphImpl( this, true, jpaMetamodel() );
|
||||
return new SubGraphImpl( this, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3617,7 +3617,7 @@ public abstract class AbstractEntityPersister
|
|||
@Override
|
||||
public boolean isAffectedByEntityGraph(LoadQueryInfluencers loadQueryInfluencers) {
|
||||
final RootGraphImplementor<?> graph = loadQueryInfluencers.getEffectiveEntityGraph().getGraph();
|
||||
return graph != null && graph.appliesTo( getEntityName() );
|
||||
return graph != null && graph.appliesTo( getEntityName(), getFactory().getJpaMetamodel() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -401,7 +401,7 @@ public abstract class AbstractCommonQueryContract implements CommonQueryContract
|
|||
final String entityName = runtimeMetamodels.getImportedName( graphString.substring( 0, separatorPosition ).trim() );
|
||||
final String graphNodes = graphString.substring( separatorPosition + 1, terminatorPosition );
|
||||
|
||||
final RootGraphImpl<?> rootGraph = new RootGraphImpl<>( null, jpaMetamodel.entity( entityName ), jpaMetamodel );
|
||||
final RootGraphImpl<?> rootGraph = new RootGraphImpl<>( null, jpaMetamodel.entity( entityName ) );
|
||||
GraphParser.parseInto( (EntityGraph<?>) rootGraph, graphNodes, getSession().getSessionFactory() );
|
||||
applyGraph( rootGraph, graphSemantic );
|
||||
}
|
||||
|
|
|
@ -562,7 +562,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
|
|||
final AppliedGraph appliedGraph = queryOptions.getAppliedGraph();
|
||||
if ( appliedGraph != null && appliedGraph.getSemantic() != null && appliedGraph.getGraph() != null ) {
|
||||
this.entityGraphTraversalState = new StandardEntityGraphTraversalStateImpl(
|
||||
appliedGraph.getSemantic(), appliedGraph.getGraph() );
|
||||
appliedGraph.getSemantic(), appliedGraph.getGraph(),
|
||||
creationContext.getSessionFactory().getJpaMetamodel()
|
||||
);
|
||||
}
|
||||
else {
|
||||
this.entityGraphTraversalState = null;
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.sql.results.graph;
|
|||
|
||||
import org.hibernate.Incubating;
|
||||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
|
@ -41,7 +42,7 @@ public interface DomainResultGraphNode {
|
|||
return null;
|
||||
}
|
||||
|
||||
default boolean appliesTo(GraphImplementor graphImplementor){
|
||||
default boolean appliesTo(GraphImplementor<?> graphImplementor, JpaMetamodel metamodel){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,9 @@ public interface FetchParent extends DomainResultGraphNode {
|
|||
return getNavigablePath().treatAs( fetchableEntityType.getEntityName() )
|
||||
.append( fetchableName );
|
||||
}
|
||||
return getNavigablePath().append( fetchableName );
|
||||
else {
|
||||
return getNavigablePath().append( fetchableName );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,7 +68,7 @@ public interface FetchParent extends DomainResultGraphNode {
|
|||
* Whereas {@link #getReferencedMappingContainer} and {@link #getReferencedMappingType} return the
|
||||
* referenced container type, this method returns the referenced part.
|
||||
*
|
||||
* E.g. for a many-to-one this methods returns the
|
||||
* E.g. for a many-to-one this method returns the
|
||||
* {@link ToOneAttributeMapping} while
|
||||
* {@link #getReferencedMappingContainer} and {@link #getReferencedMappingType} return the referenced
|
||||
* {@link org.hibernate.metamodel.mapping.EntityMappingType}.
|
||||
|
|
|
@ -10,6 +10,7 @@ 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.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.SqlAstJoinType;
|
||||
import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||
|
@ -160,8 +161,8 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean appliesTo(GraphImplementor graphImplementor) {
|
||||
return getFetchParent().appliesTo( graphImplementor );
|
||||
public boolean appliesTo(GraphImplementor<?> graphImplementor, JpaMetamodel metamodel) {
|
||||
return getFetchParent().appliesTo( graphImplementor, metamodel );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.sql.results.graph.entity;
|
|||
|
||||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.sql.results.graph.DomainResultGraphNode;
|
||||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
|
||||
|
@ -41,9 +42,10 @@ public interface EntityResultGraphNode extends DomainResultGraphNode, FetchParen
|
|||
}
|
||||
|
||||
@Override
|
||||
default boolean appliesTo(GraphImplementor graphImplementor) {
|
||||
default boolean appliesTo(GraphImplementor<?> graphImplementor, JpaMetamodel metamodel) {
|
||||
return graphImplementor.appliesTo(
|
||||
getEntityValuedModelPart().getEntityMappingType().getJavaType().getJavaTypeClass()
|
||||
getEntityValuedModelPart().getEntityMappingType().getJavaType().getJavaTypeClass(),
|
||||
metamodel
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.hibernate.metamodel.mapping.CollectionPart;
|
|||
import org.hibernate.metamodel.mapping.NonAggregatedIdentifierMapping;
|
||||
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
|
||||
import org.hibernate.metamodel.mapping.internal.EntityCollectionPart;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.sql.results.graph.EntityGraphTraversalState;
|
||||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.sql.results.graph.Fetchable;
|
||||
|
@ -29,13 +30,18 @@ import org.hibernate.sql.results.graph.Fetchable;
|
|||
public class StandardEntityGraphTraversalStateImpl implements EntityGraphTraversalState {
|
||||
|
||||
private final GraphSemantic graphSemantic;
|
||||
private final JpaMetamodel metamodel;
|
||||
private GraphImplementor<?> currentGraphContext;
|
||||
|
||||
public StandardEntityGraphTraversalStateImpl(GraphSemantic graphSemantic, RootGraphImplementor<?> rootGraphImplementor) {
|
||||
public StandardEntityGraphTraversalStateImpl(
|
||||
GraphSemantic graphSemantic,
|
||||
RootGraphImplementor<?> rootGraphImplementor,
|
||||
JpaMetamodel metamodel) {
|
||||
Objects.requireNonNull( graphSemantic, "graphSemantic cannot be null" );
|
||||
Objects.requireNonNull( rootGraphImplementor, "rootGraphImplementor cannot be null" );
|
||||
this.graphSemantic = graphSemantic;
|
||||
this.currentGraphContext = rootGraphImplementor;
|
||||
this.metamodel = metamodel;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,7 +107,7 @@ public class StandardEntityGraphTraversalStateImpl implements EntityGraphTravers
|
|||
}
|
||||
|
||||
private boolean appliesTo(FetchParent fetchParent) {
|
||||
return currentGraphContext != null && fetchParent.appliesTo( currentGraphContext );
|
||||
return currentGraphContext != null && fetchParent.appliesTo( currentGraphContext, metamodel );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -198,6 +198,6 @@ public class EntityGraphsTest extends AbstractEntityGraphTest {
|
|||
@TestForIssue( jiraKey = "HHH-14264" )
|
||||
public void testRootGraphAppliesToChildEntityClass() {
|
||||
RootGraphImplementor<GraphParsingTestEntity> rootGraphImplementor = parseGraph( GraphParsingTestEntity.class, "name, description" );
|
||||
Assert.assertTrue( rootGraphImplementor.appliesTo( GraphParsingTestSubentity.class ) );
|
||||
Assert.assertTrue( rootGraphImplementor.appliesTo( GraphParsingTestSubentity.class, entityManagerFactory().getJpaMetamodel() ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue