diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java index 940df2e4ae07..0557025955ea 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java @@ -98,25 +98,36 @@ public String getEntityName() { @Override public final Type getPropertyType(String propertyPath) { - Type result = propertyTypesByName.get(propertyPath); - if (result!=null) { - return result; + final Type cached = propertyTypesByName.get(propertyPath); + if ( cached == null ) { + final Type type = propertyType( propertyPath ); + if ( type != null ) { + propertyTypesByName.put( propertyPath, type ); + } + return type; + } + else { + return cached; } + } - result = createPropertyType(propertyPath); - if (result == null) { - //check subclasses, needed for treat() - result = getSubclassPropertyType(propertyPath); + private Type propertyType(String propertyPath) { + final Type type = createPropertyType( propertyPath ); + if ( type != null ) { + return type; } - if ("id".equals( propertyPath )) { - result = identifierType(); + //check subclasses, needed for treat() + final Type typeFromSubclass = getSubclassPropertyType( propertyPath ); + if ( typeFromSubclass != null ) { + return typeFromSubclass; } - if (result!=null) { - propertyTypesByName.put(propertyPath, result); + if ( "id".equals( propertyPath ) ) { + return identifierType(); } - return result; + + return null; } abstract Type createPropertyType(String propertyPath);