HHH-10261 - Fixing bug on creating subgraph on inherited attributes

This commit is contained in:
Oliver Breidenbach 2015-11-11 06:10:58 +01:00 committed by Andrea Boriero
parent 666a161f5f
commit 7cc7477a6f
4 changed files with 27 additions and 4 deletions

View File

@ -14,6 +14,7 @@ import java.util.Map;
import javax.persistence.AttributeNode;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.ManagedType;
import org.hibernate.graph.spi.AttributeNodeImplementor;
import org.hibernate.graph.spi.GraphNodeImplementor;
@ -62,6 +63,7 @@ public abstract class AbstractGraphNode<T> implements GraphNodeImplementor, Hibe
return copy;
}
@Override
public EntityManagerFactoryImpl getFactory() {
return entityManagerFactory;
@ -105,7 +107,7 @@ public abstract class AbstractGraphNode<T> implements GraphNodeImplementor, Hibe
protected abstract Attribute<T,?> resolveAttribute(String attributeName);
protected <X> AttributeNodeImpl<X> buildAttributeNode(Attribute<T, X> attribute) {
return new AttributeNodeImpl<X>( entityManagerFactory, attribute );
return new AttributeNodeImpl<X>( entityManagerFactory, getManagedType(), attribute );
}
protected AttributeNodeImpl addAttributeNode(AttributeNodeImpl attributeNode) {
@ -188,4 +190,6 @@ public abstract class AbstractGraphNode<T> implements GraphNodeImplementor, Hibe
public boolean containsAttribute(String name) {
return attributeNodeMap != null && attributeNodeMap.containsKey( name );
}
abstract ManagedType getManagedType();
}

View File

@ -37,12 +37,15 @@ import org.hibernate.type.Type;
public class AttributeNodeImpl<T> implements AttributeNode<T>, AttributeNodeImplementor<T>, HibernateEntityManagerFactoryAware {
private final EntityManagerFactoryImpl entityManagerFactory;
private final Attribute<?,T> attribute;
private final ManagedType managedType;
private Map<Class, Subgraph> subgraphMap;
private Map<Class, Subgraph> keySubgraphMap;
public <X> AttributeNodeImpl(EntityManagerFactoryImpl entityManagerFactory, Attribute<X,T> attribute) {
public <X> AttributeNodeImpl(
EntityManagerFactoryImpl entityManagerFactory, ManagedType managedType, Attribute<X, T> attribute) {
this.entityManagerFactory = entityManagerFactory;
this.managedType = managedType;
this.attribute = attribute;
}
@ -51,10 +54,12 @@ public class AttributeNodeImpl<T> implements AttributeNode<T>, AttributeNodeImpl
*/
private AttributeNodeImpl(
EntityManagerFactoryImpl entityManagerFactory,
Attribute<?,T> attribute,
ManagedType managedType,
Attribute<?, T> attribute,
Map<Class, Subgraph> subgraphMap,
Map<Class, Subgraph> keySubgraphMap) {
this.entityManagerFactory = entityManagerFactory;
this.managedType = managedType;
this.attribute = attribute;
this.subgraphMap = subgraphMap;
this.keySubgraphMap = keySubgraphMap;
@ -120,7 +125,9 @@ public class AttributeNodeImpl<T> implements AttributeNode<T>, AttributeNodeImpl
subgraphMap = new HashMap<Class, Subgraph>();
}
final AssociationType attributeType = (AssociationType) Helper.resolveType( sessionFactory(), attribute );
final Helper.AttributeSource attributeSource = Helper.resolveAttributeSource( sessionFactory(), managedType );
final AssociationType attributeType = (AssociationType) attributeSource.findType( attribute.getName() );
final Joinable joinable = attributeType.getAssociatedJoinable( sessionFactory() );
if ( joinable.isCollection() ) {
@ -256,6 +263,7 @@ public class AttributeNodeImpl<T> implements AttributeNode<T>, AttributeNodeImpl
public AttributeNodeImpl<T> makeImmutableCopy() {
return new AttributeNodeImpl<T>(
this.entityManagerFactory,
this.managedType,
this.attribute,
makeSafeMapCopy( subgraphMap ),
makeSafeMapCopy( keySubgraphMap )

View File

@ -13,6 +13,7 @@ import javax.persistence.Subgraph;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.EntityType;
import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.ManagedType;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.graph.spi.GraphNodeImplementor;
@ -152,4 +153,9 @@ public class EntityGraphImpl<T> extends AbstractGraphNode<T> implements EntityGr
return false;
}
@Override
ManagedType getManagedType() {
return entityType;
}
}

View File

@ -117,4 +117,9 @@ public class SubgraphImpl<T> extends AbstractGraphNode<T> implements Subgraph<T>
}
return attribute;
}
@Override
ManagedType getManagedType() {
return managedType;
}
}