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.Map;
import javax.persistence.AccessType;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.mapping.PropertyGeneration;
@ -49,6 +51,7 @@ import org.hibernate.metamodel.spi.source.RelationalValueSource;
*
* @author Steve Ebersole
* @author Hardy Ferentschik
* @author Brett Meyer
*/
public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
private static final String PATH_SEPARATOR = ".";
@ -56,12 +59,17 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
private final ValueHolder<Class<?>> classReference;
private final Map<String, AttributeOverride> attributeOverrides;
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.classReference = new ValueHolder<Class<?>>( embeddableClass.getConfiguredClass() );
this.attributeOverrides = attributeOverrides;
this.path = StringHelper.isEmpty( parentPath ) ? embeddableClass.getEmbeddedAttributeName() : parentPath + "." + embeddableClass.getEmbeddedAttributeName();
this.classAccessType = classAccessType;
}
@Override
@ -101,7 +109,7 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
@Override
public String getPropertyAccessorName() {
return embeddableClass.getClassAccessType().toString().toLowerCase();
return classAccessType.toString().toLowerCase();
}
@Override
@ -129,7 +137,8 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
new ComponentAttributeSourceImpl(
embeddable,
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.BasicAttribute;
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.source.AttributeSource;
import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource;
@ -47,7 +47,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
private static final String PATH_SEPARATOR = ".";
private final AssociationAttribute associationAttribute;
private final RootEntityClass rootEntityClass;
private final EntityClass entityClass;
private List<AttributeSource> attributeSources
= new ArrayList<AttributeSource>();
@ -56,9 +56,9 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
public CompositePluralAttributeElementSourceImpl(
AssociationAttribute associationAttribute,
RootEntityClass rootEntityClass ) {
EntityClass rootEntityClass ) {
this.associationAttribute = associationAttribute;
this.rootEntityClass = rootEntityClass;
this.entityClass = rootEntityClass;
buildAttributeSources();
}
@ -123,7 +123,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
}
private void buildAttributeSources() {
EmbeddableClass embeddableClass = rootEntityClass
EmbeddableClass embeddableClass = entityClass
.getCollectionEmbeddedClasses()
.get( associationAttribute.getName() );
@ -133,8 +133,8 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) {
AttributeOverride attributeOverride = null;
String tmp = getPath() + PATH_SEPARATOR + attribute.getName();
if ( rootEntityClass.getAttributeOverrideMap().containsKey( tmp ) ) {
attributeOverride = rootEntityClass.getAttributeOverrideMap().get( tmp );
if ( entityClass.getAttributeOverrideMap().containsKey( tmp ) ) {
attributeOverride = entityClass.getAttributeOverrideMap().get( tmp );
}
attribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() );
attributeSources.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
@ -145,7 +145,8 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
new ComponentAttributeSourceImpl(
embeddable,
getPath(),
createAggregatedOverrideMap( embeddableClass, rootEntityClass.getAttributeOverrideMap() )
createAggregatedOverrideMap( embeddableClass, entityClass.getAttributeOverrideMap() ),
embeddable.getClassAccessType()
)
);
}

View File

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

View File

@ -109,7 +109,7 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
case ELEMENT_COLLECTION_EMBEDDABLE: {
// TODO: cascadeStyles?
return new CompositePluralAttributeElementSourceImpl(
associationAttribute, (RootEntityClass) entityClass );
associationAttribute, entityClass );
}
}
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...
Map<String, AttributeOverride> overrides = getEntityClass().getAttributeOverrideMap();
componentAttributeSource = new ComponentAttributeSourceImpl( embeddableClass, "", overrides );
componentAttributeSource = new ComponentAttributeSourceImpl( embeddableClass, "", overrides, embeddableClass.getClassAccessType() );
}
@Override

View File

@ -76,7 +76,7 @@ public abstract class AbstractComponentAttributeSourceImpl extends AbstractHbmSo
this.componentClassReference = makeClassReference( componentSourceElement.getClazz() );
this.logicalTableName = logicalTableName;
this.path = parentContainer.getPath() + '.' + componentSourceElement.getName();
this.subAttributeSources = buildAttributeSources();
}