HHH-7701 Entity's access type is overriden if an attribute's class has

@AccessType
This commit is contained in:
brmeyer 2012-12-04 16:36:33 -05:00
parent 4af03102e4
commit 1ca4be92da
6 changed files with 26 additions and 15 deletions

View File

@ -29,6 +29,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.persistence.AccessType;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.ValueHolder; import org.hibernate.internal.util.ValueHolder;
import org.hibernate.mapping.PropertyGeneration; import org.hibernate.mapping.PropertyGeneration;
@ -49,6 +51,7 @@ import org.hibernate.metamodel.spi.source.RelationalValueSource;
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Hardy Ferentschik * @author Hardy Ferentschik
* @author Brett Meyer
*/ */
public class ComponentAttributeSourceImpl implements ComponentAttributeSource { public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
private static final String PATH_SEPARATOR = "."; private static final String PATH_SEPARATOR = ".";
@ -56,12 +59,17 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
private final ValueHolder<Class<?>> classReference; private final ValueHolder<Class<?>> classReference;
private final Map<String, AttributeOverride> attributeOverrides; private final Map<String, AttributeOverride> attributeOverrides;
private final String path; private final String path;
private final AccessType classAccessType;
public ComponentAttributeSourceImpl(EmbeddableClass embeddableClass, String parentPath, Map<String, AttributeOverride> attributeOverrides) { public ComponentAttributeSourceImpl(EmbeddableClass embeddableClass,
String parentPath,
Map<String, AttributeOverride> attributeOverrides,
AccessType classAccessType) {
this.embeddableClass = embeddableClass; this.embeddableClass = embeddableClass;
this.classReference = new ValueHolder<Class<?>>( embeddableClass.getConfiguredClass() ); this.classReference = new ValueHolder<Class<?>>( embeddableClass.getConfiguredClass() );
this.attributeOverrides = attributeOverrides; this.attributeOverrides = attributeOverrides;
this.path = StringHelper.isEmpty( parentPath ) ? embeddableClass.getEmbeddedAttributeName() : parentPath + "." + embeddableClass.getEmbeddedAttributeName(); this.path = StringHelper.isEmpty( parentPath ) ? embeddableClass.getEmbeddedAttributeName() : parentPath + "." + embeddableClass.getEmbeddedAttributeName();
this.classAccessType = classAccessType;
} }
@Override @Override
@ -101,7 +109,7 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
@Override @Override
public String getPropertyAccessorName() { public String getPropertyAccessorName() {
return embeddableClass.getClassAccessType().toString().toLowerCase(); return classAccessType.toString().toLowerCase();
} }
@Override @Override
@ -129,7 +137,8 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
new ComponentAttributeSourceImpl( new ComponentAttributeSourceImpl(
embeddable, embeddable,
getPath(), getPath(),
createAggregatedOverrideMap() createAggregatedOverrideMap(),
classAccessType
) )
); );
} }

View File

@ -32,7 +32,7 @@ import org.hibernate.metamodel.internal.source.annotations.attribute.Association
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride; import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute; import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass; import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass;
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass; import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
import org.hibernate.metamodel.spi.binding.CascadeType; import org.hibernate.metamodel.spi.binding.CascadeType;
import org.hibernate.metamodel.spi.source.AttributeSource; import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource; import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource;
@ -47,7 +47,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
private static final String PATH_SEPARATOR = "."; private static final String PATH_SEPARATOR = ".";
private final AssociationAttribute associationAttribute; private final AssociationAttribute associationAttribute;
private final RootEntityClass rootEntityClass; private final EntityClass entityClass;
private List<AttributeSource> attributeSources private List<AttributeSource> attributeSources
= new ArrayList<AttributeSource>(); = new ArrayList<AttributeSource>();
@ -56,9 +56,9 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
public CompositePluralAttributeElementSourceImpl( public CompositePluralAttributeElementSourceImpl(
AssociationAttribute associationAttribute, AssociationAttribute associationAttribute,
RootEntityClass rootEntityClass ) { EntityClass rootEntityClass ) {
this.associationAttribute = associationAttribute; this.associationAttribute = associationAttribute;
this.rootEntityClass = rootEntityClass; this.entityClass = rootEntityClass;
buildAttributeSources(); buildAttributeSources();
} }
@ -123,7 +123,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
} }
private void buildAttributeSources() { private void buildAttributeSources() {
EmbeddableClass embeddableClass = rootEntityClass EmbeddableClass embeddableClass = entityClass
.getCollectionEmbeddedClasses() .getCollectionEmbeddedClasses()
.get( associationAttribute.getName() ); .get( associationAttribute.getName() );
@ -133,8 +133,8 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) { for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) {
AttributeOverride attributeOverride = null; AttributeOverride attributeOverride = null;
String tmp = getPath() + PATH_SEPARATOR + attribute.getName(); String tmp = getPath() + PATH_SEPARATOR + attribute.getName();
if ( rootEntityClass.getAttributeOverrideMap().containsKey( tmp ) ) { if ( entityClass.getAttributeOverrideMap().containsKey( tmp ) ) {
attributeOverride = rootEntityClass.getAttributeOverrideMap().get( tmp ); attributeOverride = entityClass.getAttributeOverrideMap().get( tmp );
} }
attribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() ); attribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() );
attributeSources.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) ); attributeSources.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
@ -145,7 +145,8 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
new ComponentAttributeSourceImpl( new ComponentAttributeSourceImpl(
embeddable, embeddable,
getPath(), getPath(),
createAggregatedOverrideMap( embeddableClass, rootEntityClass.getAttributeOverrideMap() ) createAggregatedOverrideMap( embeddableClass, entityClass.getAttributeOverrideMap() ),
embeddable.getClassAccessType()
) )
); );
} }

View File

@ -223,7 +223,8 @@ public class EntitySourceImpl implements EntitySource {
new ComponentAttributeSourceImpl( new ComponentAttributeSourceImpl(
component, component,
"", "",
entityClass.getAttributeOverrideMap() entityClass.getAttributeOverrideMap(),
entityClass.getClassAccessType()
) )
); );
} }

View File

@ -109,7 +109,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
case ELEMENT_COLLECTION_EMBEDDABLE: { case ELEMENT_COLLECTION_EMBEDDABLE: {
// TODO: cascadeStyles? // TODO: cascadeStyles?
return new CompositePluralAttributeElementSourceImpl( return new CompositePluralAttributeElementSourceImpl(
associationAttribute, (RootEntityClass) entityClass ); associationAttribute, entityClass );
} }
} }
throw new AssertionError( "Unexpected attribute nature for a association:" + associationAttribute.getNature() ); throw new AssertionError( "Unexpected attribute nature for a association:" + associationAttribute.getNature() );

View File

@ -193,7 +193,7 @@ public class RootEntitySourceImpl extends EntitySourceImpl implements RootEntity
// todo : no idea how to obtain overrides here... // todo : no idea how to obtain overrides here...
Map<String, AttributeOverride> overrides = getEntityClass().getAttributeOverrideMap(); Map<String, AttributeOverride> overrides = getEntityClass().getAttributeOverrideMap();
componentAttributeSource = new ComponentAttributeSourceImpl( embeddableClass, "", overrides ); componentAttributeSource = new ComponentAttributeSourceImpl( embeddableClass, "", overrides, embeddableClass.getClassAccessType() );
} }
@Override @Override