diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java index 28ade5300..4213372c7 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCEnhancer.java @@ -657,13 +657,6 @@ public class PCEnhancer { return "set" + StringUtils.capitalize(fmd.getName()); } - /** - * Return the name of the getter method for the given field. - */ - private static String getGetterName(FieldMetaData fmd) { - return "get" + StringUtils.capitalize(fmd.getName()); - } - /** * Return the field returned by the given method, or null if none. * Package-protected and static for testing. @@ -3325,8 +3318,12 @@ public class PCEnhancer { } private boolean setVisibilityToSuperMethod(BCMethod method) { - BCMethod superMeth = _managedType.getMethods(method.getName(), - method.getParamTypes())[0]; + BCMethod[] methods = _managedType.getMethods(method.getName(), + method.getParamTypes()); + if (methods.length == 0) + throw new UserException(_loc.get("no-accessor", + _managedType.getName(), method.getName())); + BCMethod superMeth = methods[0]; if (superMeth.isPrivate()) { method.makePrivate(); return true; @@ -3348,7 +3345,9 @@ public class PCEnhancer { * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { - String methName = getGetterName(fmd); + String methName = "get" + StringUtils.capitalize(fmd.getName()); + if (_managedType.getMethods(methName, new Class[0]).length == 0) + methName = "is" + StringUtils.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); diff --git a/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties b/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties index 1d71881e3..c1e12f2b0 100644 --- a/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties +++ b/openjpa-kernel/src/main/resources/org/apache/openjpa/enhance/localizer.properties @@ -194,3 +194,4 @@ subclasser-fetch-group-override: The field {1} in type {0} is configured to be \ lazily loaded, but lazy loading is not available for classes that use field\ access when not running the OpenJPA enhancer or when dynamic class \ redefinition is not available. +no-accessor: Could not find method called {0} in type {1}. \ No newline at end of file