Skip to content

Commit f30dd6f

Browse files
committed
HHH-18928 Consider class-level default PROPERTY access type
1 parent adeb83c commit f30dd6f

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
@@ -19,16 +19,21 @@
1919
*/
2020
public class PropertyAccessStrategyEnhancedImpl implements PropertyAccessStrategy {
2121
public static PropertyAccessStrategyEnhancedImpl with(AccessType getterAccessType) {
22-
if ( getterAccessType == AccessType.FIELD ) {
23-
return FIELD;
22+
if ( getterAccessType == null ) {
23+
return STANDARD;
2424
}
25-
return STANDARD;
25+
26+
return switch ( getterAccessType ) {
27+
case FIELD -> FIELD;
28+
case PROPERTY -> PROPERTY;
29+
};
2630
}
2731

2832
private final @Nullable AccessType getterAccessType;
2933

3034
public static PropertyAccessStrategyEnhancedImpl STANDARD = new PropertyAccessStrategyEnhancedImpl( null );
3135
public static PropertyAccessStrategyEnhancedImpl FIELD = new PropertyAccessStrategyEnhancedImpl( AccessType.FIELD );
36+
public static PropertyAccessStrategyEnhancedImpl PROPERTY = new PropertyAccessStrategyEnhancedImpl( AccessType.PROPERTY );
3237

3338
public PropertyAccessStrategyEnhancedImpl(@Nullable AccessType getterAccessType) {
3439
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
@@ -6,6 +6,7 @@
66

77
import org.hibernate.HibernateException;
88
import org.hibernate.boot.registry.selector.spi.StrategySelector;
9+
import org.hibernate.boot.spi.AccessType;
910
import org.hibernate.internal.util.StringHelper;
1011
import org.hibernate.metamodel.RepresentationMode;
1112
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
@@ -38,9 +39,12 @@ public PropertyAccessStrategy resolvePropertyAccessStrategy(
3839
|| BuiltInPropertyAccessStrategies.MIXED.getExternalName().equals( explicitAccessStrategyName ) ) {
3940
//type-cache-pollution agent: it's crucial to use the ManagedTypeHelper rather than attempting a direct cast
4041
if ( isManagedType( containerClass ) ) {
41-
if ( BuiltInPropertyAccessStrategies.FIELD.getExternalName().equals( explicitAccessStrategyName ) ) {
42+
if ( AccessType.FIELD.getType().equals( explicitAccessStrategyName ) ) {
4243
return PropertyAccessStrategyEnhancedImpl.FIELD;
4344
}
45+
else if ( AccessType.PROPERTY.getType().equals( explicitAccessStrategyName ) ) {
46+
return PropertyAccessStrategyEnhancedImpl.PROPERTY;
47+
}
4448
return PropertyAccessStrategyEnhancedImpl.STANDARD;
4549
}
4650
}

0 commit comments

Comments
 (0)