Skip to content

Commit 46a149d

Browse files
committed
HHH-18928 Consider class-level default PROPERTY access type
1 parent 3cbc98b commit 46a149d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,21 @@
2121
*/
2222
public class PropertyAccessStrategyEnhancedImpl implements PropertyAccessStrategy {
2323
public static PropertyAccessStrategyEnhancedImpl with(AccessType getterAccessType) {
24-
if ( getterAccessType == AccessType.FIELD ) {
25-
return FIELD;
24+
if ( getterAccessType == null ) {
25+
return STANDARD;
2626
}
27-
return STANDARD;
27+
28+
return switch ( getterAccessType ) {
29+
case FIELD -> FIELD;
30+
case PROPERTY -> PROPERTY;
31+
};
2832
}
2933

3034
private final @Nullable AccessType getterAccessType;
3135

3236
public static PropertyAccessStrategyEnhancedImpl STANDARD = new PropertyAccessStrategyEnhancedImpl( null );
3337
public static PropertyAccessStrategyEnhancedImpl FIELD = new PropertyAccessStrategyEnhancedImpl( AccessType.FIELD );
38+
public static PropertyAccessStrategyEnhancedImpl PROPERTY = new PropertyAccessStrategyEnhancedImpl( AccessType.PROPERTY );
3439

3540
public PropertyAccessStrategyEnhancedImpl(@Nullable AccessType getterAccessType) {
3641
this.getterAccessType = getterAccessType;

hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import org.hibernate.HibernateException;
1010
import org.hibernate.boot.registry.selector.spi.StrategySelector;
11+
import org.hibernate.boot.spi.AccessType;
1112
import org.hibernate.internal.util.StringHelper;
1213
import org.hibernate.metamodel.RepresentationMode;
1314
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
@@ -40,9 +41,12 @@ public PropertyAccessStrategy resolvePropertyAccessStrategy(
4041
|| BuiltInPropertyAccessStrategies.MIXED.getExternalName().equals( explicitAccessStrategyName ) ) {
4142
//type-cache-pollution agent: it's crucial to use the ManagedTypeHelper rather than attempting a direct cast
4243
if ( isManagedType( containerClass ) ) {
43-
if ( BuiltInPropertyAccessStrategies.FIELD.getExternalName().equals( explicitAccessStrategyName ) ) {
44+
if ( AccessType.FIELD.getType().equals( explicitAccessStrategyName ) ) {
4445
return PropertyAccessStrategyEnhancedImpl.FIELD;
4546
}
47+
else if ( AccessType.PROPERTY.getType().equals( explicitAccessStrategyName ) ) {
48+
return PropertyAccessStrategyEnhancedImpl.PROPERTY;
49+
}
4650
return PropertyAccessStrategyEnhancedImpl.STANDARD;
4751
}
4852
}

0 commit comments

Comments
 (0)