Skip to content

Commit f5197a3

Browse files
committed
HHH-10309 - HHH-10242 is too aggressive in cases of FIELD access
(cherry picked from commit 1183a47)
1 parent c7abe77 commit f5197a3

File tree

4 files changed

+312
-140
lines changed

4 files changed

+312
-140
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,32 +1468,23 @@ private static void bindDiscriminatorColumnToRootPersistentClass(
14681468

14691469
/**
14701470
* @param elements List of {@code ProperyData} instances
1471-
* @param defaultAccessType The default value access strategy which has to be used in case no explicit local access
1472-
* strategy is used
14731471
* @param propertyContainer Metadata about a class and its properties
14741472
*
14751473
* @return the number of id properties found while iterating the elements of {@code annotatedClass} using
14761474
* the determined access strategy, {@code false} otherwise.
14771475
*/
14781476
static int addElementsOfClass(
14791477
List<PropertyData> elements,
1480-
AccessType defaultAccessType,
14811478
PropertyContainer propertyContainer,
14821479
MetadataBuildingContext context) {
14831480
int idPropertyCounter = 0;
1484-
AccessType accessType = defaultAccessType;
14851481

1486-
if ( propertyContainer.hasExplicitAccessStrategy() ) {
1487-
accessType = propertyContainer.getExplicitAccessStrategy();
1488-
}
1489-
1490-
Collection<XProperty> properties = propertyContainer.getProperties( accessType );
1482+
Collection<XProperty> properties = propertyContainer.getProperties();
14911483
for ( XProperty p : properties ) {
14921484
final int currentIdPropertyCounter = addProperty(
14931485
propertyContainer,
14941486
p,
14951487
elements,
1496-
accessType.getType(),
14971488
context
14981489
);
14991490
idPropertyCounter += currentIdPropertyCounter;
@@ -1505,15 +1496,14 @@ private static int addProperty(
15051496
PropertyContainer propertyContainer,
15061497
XProperty property,
15071498
List<PropertyData> annElts,
1508-
String propertyAccessor,
15091499
MetadataBuildingContext context) {
15101500
final XClass declaringClass = propertyContainer.getDeclaringClass();
15111501
final XClass entity = propertyContainer.getEntityAtStake();
15121502
int idPropertyCounter = 0;
15131503
PropertyData propertyAnnotatedElement = new PropertyInferredData(
15141504
declaringClass,
15151505
property,
1516-
propertyAccessor,
1506+
propertyContainer.getClassLevelAccessType().getType(),
15171507
context.getBuildingOptions().getReflectionManager()
15181508
);
15191509

@@ -1560,7 +1550,7 @@ else if ( prop.isAnnotationPresent( JoinColumns.class ) ) {
15601550
//same dec
15611551
prop,
15621552
// the actual @XToOne property
1563-
propertyAccessor,
1553+
propertyContainer.getClassLevelAccessType().getType(),
15641554
//TODO we should get the right accessor but the same as id would do
15651555
context.getBuildingOptions().getReflectionManager()
15661556
);
@@ -2560,24 +2550,24 @@ public static Component fillComponent(
25602550
baseClassElements = new ArrayList<PropertyData>();
25612551
baseReturnedClassOrElement = baseInferredData.getClassOrElement();
25622552
bindTypeDefs( baseReturnedClassOrElement, buildingContext );
2563-
PropertyContainer propContainer = new PropertyContainer( baseReturnedClassOrElement, xClassProcessed );
2564-
addElementsOfClass( baseClassElements, propertyAccessor, propContainer, buildingContext );
2553+
PropertyContainer propContainer = new PropertyContainer( baseReturnedClassOrElement, xClassProcessed, propertyAccessor );
2554+
addElementsOfClass( baseClassElements, propContainer, buildingContext );
25652555
for ( PropertyData element : baseClassElements ) {
25662556
orderedBaseClassElements.put( element.getPropertyName(), element );
25672557
}
25682558
}
25692559

25702560
//embeddable elements can have type defs
25712561
bindTypeDefs( returnedClassOrElement, buildingContext );
2572-
PropertyContainer propContainer = new PropertyContainer( returnedClassOrElement, xClassProcessed );
2573-
addElementsOfClass( classElements, propertyAccessor, propContainer, buildingContext );
2562+
PropertyContainer propContainer = new PropertyContainer( returnedClassOrElement, xClassProcessed, propertyAccessor );
2563+
addElementsOfClass( classElements, propContainer, buildingContext );
25742564

25752565
//add elements of the embeddable superclass
25762566
XClass superClass = xClassProcessed.getSuperclass();
25772567
while ( superClass != null && superClass.isAnnotationPresent( MappedSuperclass.class ) ) {
25782568
//FIXME: proper support of typevariables incl var resolved at upper levels
2579-
propContainer = new PropertyContainer( superClass, xClassProcessed );
2580-
addElementsOfClass( classElements, propertyAccessor, propContainer, buildingContext );
2569+
propContainer = new PropertyContainer( superClass, xClassProcessed, propertyAccessor );
2570+
addElementsOfClass( classElements, propContainer, buildingContext );
25812571
superClass = superClass.getSuperclass();
25822572
}
25832573
if ( baseClassElements != null ) {
@@ -2790,9 +2780,11 @@ private static PropertyData getUniqueIdPropertyFromBaseClass(
27902780
List<PropertyData> baseClassElements = new ArrayList<PropertyData>();
27912781
XClass baseReturnedClassOrElement = baseInferredData.getClassOrElement();
27922782
PropertyContainer propContainer = new PropertyContainer(
2793-
baseReturnedClassOrElement, inferredData.getPropertyClass()
2783+
baseReturnedClassOrElement,
2784+
inferredData.getPropertyClass(),
2785+
propertyAccessor
27942786
);
2795-
addElementsOfClass( baseClassElements, propertyAccessor, propContainer, context );
2787+
addElementsOfClass( baseClassElements, propContainer, context );
27962788
//Id properties are on top and there is only one
27972789
return baseClassElements.get( 0 );
27982790
}

hibernate-core/src/main/java/org/hibernate/cfg/InheritanceState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ public ElementsToProcess getElementsToProcess() {
216216
for ( XClass classToProcessForMappedSuperclass : classesToProcessForMappedSuperclass ) {
217217
PropertyContainer propertyContainer = new PropertyContainer(
218218
classToProcessForMappedSuperclass,
219-
clazz
219+
clazz,
220+
accessType
220221
);
221222
int currentIdPropertyCount = AnnotationBinder.addElementsOfClass(
222223
elements,
223-
accessType,
224224
propertyContainer,
225225
buildingContext
226226
);

0 commit comments

Comments
 (0)