Skip to content

Commit e601af7

Browse files
committed
HHH-19140 Fix for issue
1 parent b8974de commit e601af7

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ private static Method setterOrNullBySetterName(Class<?>[] interfaces, String set
715715
return setter;
716716
}
717717

718-
private static boolean shouldSkipInterfaceCheck(final Class<?> anInterface) {
718+
public static boolean shouldSkipInterfaceCheck(final Class<?> anInterface) {
719719
final String interfaceName = anInterface.getName();
720720
//Skip checking any interface that we've added via bytecode enhancement:
721721
//there's many of those, and it's pointless to look there.

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static org.hibernate.internal.util.ReflectHelper.NO_PARAM_SIGNATURE;
3333
import static org.hibernate.internal.util.ReflectHelper.findField;
3434
import static org.hibernate.internal.util.ReflectHelper.isRecord;
35+
import static org.hibernate.internal.util.ReflectHelper.shouldSkipInterfaceCheck;
3536

3637
/**
3738
* @author Steve Ebersole
@@ -82,9 +83,56 @@ public static AccessType getAccessType(Class<?> containerJavaType, String proper
8283
&& field.isAnnotationPresent( Access.class )
8384
&& !field.isAnnotationPresent( Transient.class )
8485
&& !Modifier.isStatic( field.getModifiers() ) ) {
85-
return AccessType.FIELD;
86+
AccessType accessType = getAccessTypeOrNull(field);
87+
return accessType == null ? AccessType.FIELD : accessType;
88+
//return AccessType.FIELD;
8689
}
8790

91+
Class<?> checkClass = containerClass;
92+
AccessType accessType = null;
93+
while ( accessType == null && checkClass != null ) {
94+
if ( checkClass.equals( Object.class ) ) {
95+
break;
96+
}
97+
accessType = getGetterAccessTypeOrNull( checkClass, propertyName );
98+
99+
// if no accessType found yet, check all implemented interfaces
100+
if ( accessType == null ) {
101+
accessType = getGetterAccessTypeOrNull( checkClass.getInterfaces(), propertyName );
102+
}
103+
104+
checkClass = checkClass.getSuperclass();
105+
}
106+
107+
return accessType;
108+
}
109+
110+
private static @Nullable AccessType getGetterAccessTypeOrNull(Class<?>[] interfaces, String propertyName) {
111+
AccessType accessType = null;
112+
for ( int i = 0; accessType == null && i < interfaces.length; ++i ) {
113+
final Class<?> anInterface = interfaces[i];
114+
if ( shouldSkipInterfaceCheck( anInterface ) ) {
115+
continue;
116+
}
117+
accessType = getGetterAccessTypeOrNull( anInterface, propertyName );
118+
if ( accessType == null ) {
119+
// if no getter found yet, check all implemented interfaces of interface
120+
accessType = getGetterAccessTypeOrNull( anInterface.getInterfaces(), propertyName );
121+
}
122+
}
123+
return accessType;
124+
}
125+
126+
private static @Nullable AccessType getGetterAccessTypeOrNull(Class<?> containerClass, String propertyName){
127+
if ( isRecord( containerClass ) ) {
128+
try {
129+
containerClass.getMethod( propertyName, NO_PARAM_SIGNATURE );
130+
return AccessType.PROPERTY;
131+
}
132+
catch (NoSuchMethodException e) {
133+
// Ignore
134+
}
135+
}
88136
for ( Method method : containerClass.getDeclaredMethods() ) {
89137
// if the method has parameters, skip it
90138
if ( method.getParameterCount() != 0 ) {

0 commit comments

Comments
 (0)