Skip to content

Commit 83350f9

Browse files
committed
Fix Scala-generated QueryDSL path classes.
Resolve the static field of the given type inside the specified domain class by considering both the provided Java and Scala object path class names. Useful for handling of Scala-generated QueryDSL path classes. Issue: 1392
1 parent fe885b3 commit 83350f9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java

+18
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public <T> EntityPath<T> createPath(Class<T> domainClass) {
7171
Class<?> pathClass = ClassUtils.forName(pathClassName, domainClass.getClassLoader());
7272

7373
return getStaticFieldOfType(pathClass)//
74+
.or(() -> getFieldForScalaObject(domainClass, pathClassName))//
7475
.map(it -> (EntityPath<T>) ReflectionUtils.getField(it, null))//
7576
.orElseThrow(() -> new IllegalStateException(String.format(NO_FIELD_FOUND_TEMPLATE, pathClass)));
7677

@@ -80,6 +81,23 @@ public <T> EntityPath<T> createPath(Class<T> domainClass) {
8081
}
8182
}
8283

84+
/**
85+
* Resolves the static field of the given type inside the specified domain class.
86+
* Useful for handling Scala-generated QueryDSL path classes.
87+
*
88+
* @param domainClass The domain class for which the static field needs to be resolved.
89+
* @param javaPathClassName The Java path class name without the "$" suffix.
90+
* @return
91+
*/
92+
private <T> Optional<Field> getFieldForScalaObject(Class<T> domainClass, String javaPathClassName) {
93+
try {
94+
Class<?> scalaPathClass = ClassUtils.forName(javaPathClassName + "$", domainClass.getClassLoader());
95+
return getStaticFieldOfType(scalaPathClass);
96+
} catch (ClassNotFoundException e) {
97+
throw new RuntimeException(e);
98+
}
99+
}
100+
83101
/**
84102
* Returns the first static field of the given type inside the given type.
85103
*

0 commit comments

Comments
 (0)