Skip to content

Commit e5dd1bd

Browse files
gavinkingyrodiere
authored andcommitted
HHH-19570 HQL with jpamodelgen fails compilation when querying by natural id named id
1 parent e9f2787 commit e5dd1bd

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/validation/MockEntityPersister.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,36 @@ public String getEntityName() {
9898

9999
@Override
100100
public final Type getPropertyType(String propertyPath) {
101-
Type result = propertyTypesByName.get(propertyPath);
102-
if (result!=null) {
103-
return result;
101+
final Type cached = propertyTypesByName.get(propertyPath);
102+
if ( cached == null ) {
103+
final Type type = propertyType( propertyPath );
104+
if ( type != null ) {
105+
propertyTypesByName.put( propertyPath, type );
106+
}
107+
return type;
108+
}
109+
else {
110+
return cached;
104111
}
112+
}
105113

106-
result = createPropertyType(propertyPath);
107-
if (result == null) {
108-
//check subclasses, needed for treat()
109-
result = getSubclassPropertyType(propertyPath);
114+
private Type propertyType(String propertyPath) {
115+
final Type type = createPropertyType( propertyPath );
116+
if ( type != null ) {
117+
return type;
110118
}
111119

112-
if ("id".equals( propertyPath )) {
113-
result = identifierType();
120+
//check subclasses, needed for treat()
121+
final Type typeFromSubclass = getSubclassPropertyType( propertyPath );
122+
if ( typeFromSubclass != null ) {
123+
return typeFromSubclass;
114124
}
115125

116-
if (result!=null) {
117-
propertyTypesByName.put(propertyPath, result);
126+
if ( "id".equals( propertyPath ) ) {
127+
return identifierType();
118128
}
119-
return result;
129+
130+
return null;
120131
}
121132

122133
abstract Type createPropertyType(String propertyPath);

0 commit comments

Comments
 (0)