Skip to content

Commit 1ca4be9

Browse files
committed
HHH-7701 Entity's access type is overriden if an attribute's class has
@accesstype
1 parent 4af0310 commit 1ca4be9

File tree

6 files changed

+26
-15
lines changed

6 files changed

+26
-15
lines changed

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/ComponentAttributeSourceImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.List;
3030
import java.util.Map;
3131

32+
import javax.persistence.AccessType;
33+
3234
import org.hibernate.internal.util.StringHelper;
3335
import org.hibernate.internal.util.ValueHolder;
3436
import org.hibernate.mapping.PropertyGeneration;
@@ -49,19 +51,25 @@
4951
*
5052
* @author Steve Ebersole
5153
* @author Hardy Ferentschik
54+
* @author Brett Meyer
5255
*/
5356
public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
5457
private static final String PATH_SEPARATOR = ".";
5558
private final EmbeddableClass embeddableClass;
5659
private final ValueHolder<Class<?>> classReference;
5760
private final Map<String, AttributeOverride> attributeOverrides;
5861
private final String path;
62+
private final AccessType classAccessType;
5963

60-
public ComponentAttributeSourceImpl(EmbeddableClass embeddableClass, String parentPath, Map<String, AttributeOverride> attributeOverrides) {
64+
public ComponentAttributeSourceImpl(EmbeddableClass embeddableClass,
65+
String parentPath,
66+
Map<String, AttributeOverride> attributeOverrides,
67+
AccessType classAccessType) {
6168
this.embeddableClass = embeddableClass;
6269
this.classReference = new ValueHolder<Class<?>>( embeddableClass.getConfiguredClass() );
6370
this.attributeOverrides = attributeOverrides;
6471
this.path = StringHelper.isEmpty( parentPath ) ? embeddableClass.getEmbeddedAttributeName() : parentPath + "." + embeddableClass.getEmbeddedAttributeName();
72+
this.classAccessType = classAccessType;
6573
}
6674

6775
@Override
@@ -101,7 +109,7 @@ public String getExplicitTuplizerClassName() {
101109

102110
@Override
103111
public String getPropertyAccessorName() {
104-
return embeddableClass.getClassAccessType().toString().toLowerCase();
112+
return classAccessType.toString().toLowerCase();
105113
}
106114

107115
@Override
@@ -129,7 +137,8 @@ public List<AttributeSource> initialize() {
129137
new ComponentAttributeSourceImpl(
130138
embeddable,
131139
getPath(),
132-
createAggregatedOverrideMap()
140+
createAggregatedOverrideMap(),
141+
classAccessType
133142
)
134143
);
135144
}

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/CompositePluralAttributeElementSourceImpl.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
3333
import org.hibernate.metamodel.internal.source.annotations.attribute.BasicAttribute;
3434
import org.hibernate.metamodel.internal.source.annotations.entity.EmbeddableClass;
35-
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
35+
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
3636
import org.hibernate.metamodel.spi.binding.CascadeType;
3737
import org.hibernate.metamodel.spi.source.AttributeSource;
3838
import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource;
@@ -47,7 +47,7 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
4747
private static final String PATH_SEPARATOR = ".";
4848

4949
private final AssociationAttribute associationAttribute;
50-
private final RootEntityClass rootEntityClass;
50+
private final EntityClass entityClass;
5151

5252
private List<AttributeSource> attributeSources
5353
= new ArrayList<AttributeSource>();
@@ -56,9 +56,9 @@ public class CompositePluralAttributeElementSourceImpl implements CompositePlura
5656

5757
public CompositePluralAttributeElementSourceImpl(
5858
AssociationAttribute associationAttribute,
59-
RootEntityClass rootEntityClass ) {
59+
EntityClass rootEntityClass ) {
6060
this.associationAttribute = associationAttribute;
61-
this.rootEntityClass = rootEntityClass;
61+
this.entityClass = rootEntityClass;
6262

6363
buildAttributeSources();
6464
}
@@ -123,7 +123,7 @@ public String getExplicitTuplizerClassName() {
123123
}
124124

125125
private void buildAttributeSources() {
126-
EmbeddableClass embeddableClass = rootEntityClass
126+
EmbeddableClass embeddableClass = entityClass
127127
.getCollectionEmbeddedClasses()
128128
.get( associationAttribute.getName() );
129129

@@ -133,8 +133,8 @@ private void buildAttributeSources() {
133133
for ( BasicAttribute attribute : embeddableClass.getSimpleAttributes() ) {
134134
AttributeOverride attributeOverride = null;
135135
String tmp = getPath() + PATH_SEPARATOR + attribute.getName();
136-
if ( rootEntityClass.getAttributeOverrideMap().containsKey( tmp ) ) {
137-
attributeOverride = rootEntityClass.getAttributeOverrideMap().get( tmp );
136+
if ( entityClass.getAttributeOverrideMap().containsKey( tmp ) ) {
137+
attributeOverride = entityClass.getAttributeOverrideMap().get( tmp );
138138
}
139139
attribute.setNaturalIdMutability( embeddableClass.getNaturalIdMutability() );
140140
attributeSources.add( new SingularAttributeSourceImpl( attribute, attributeOverride ) );
@@ -145,7 +145,8 @@ private void buildAttributeSources() {
145145
new ComponentAttributeSourceImpl(
146146
embeddable,
147147
getPath(),
148-
createAggregatedOverrideMap( embeddableClass, rootEntityClass.getAttributeOverrideMap() )
148+
createAggregatedOverrideMap( embeddableClass, entityClass.getAttributeOverrideMap() ),
149+
embeddable.getClassAccessType()
149150
)
150151
);
151152
}

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/EntitySourceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ public List<AttributeSource> attributeSources() {
223223
new ComponentAttributeSourceImpl(
224224
component,
225225
"",
226-
entityClass.getAttributeOverrideMap()
226+
entityClass.getAttributeOverrideMap(),
227+
entityClass.getClassAccessType()
227228
)
228229
);
229230
}

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/PluralAttributeSourceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private PluralAttributeElementSource determineElementSource() {
109109
case ELEMENT_COLLECTION_EMBEDDABLE: {
110110
// TODO: cascadeStyles?
111111
return new CompositePluralAttributeElementSourceImpl(
112-
associationAttribute, (RootEntityClass) entityClass );
112+
associationAttribute, entityClass );
113113
}
114114
}
115115
throw new AssertionError( "Unexpected attribute nature for a association:" + associationAttribute.getNature() );

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/RootEntitySourceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public AggregatedCompositeIdentifierSourceImpl(RootEntitySourceImpl rootEntitySo
193193

194194
// todo : no idea how to obtain overrides here...
195195
Map<String, AttributeOverride> overrides = getEntityClass().getAttributeOverrideMap();
196-
componentAttributeSource = new ComponentAttributeSourceImpl( embeddableClass, "", overrides );
196+
componentAttributeSource = new ComponentAttributeSourceImpl( embeddableClass, "", overrides, embeddableClass.getClassAccessType() );
197197
}
198198

199199
@Override

hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/hbm/AbstractComponentAttributeSourceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected AbstractComponentAttributeSourceImpl(
7676
this.componentClassReference = makeClassReference( componentSourceElement.getClazz() );
7777
this.logicalTableName = logicalTableName;
7878
this.path = parentContainer.getPath() + '.' + componentSourceElement.getName();
79-
79+
8080
this.subAttributeSources = buildAttributeSources();
8181
}
8282

0 commit comments

Comments
 (0)