diff --git a/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java b/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java index 46696242ba..8718eb2dad 100644 --- a/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java +++ b/src/main/java/org/springframework/data/querydsl/SimpleEntityPathResolver.java @@ -31,6 +31,7 @@ * * @author Oliver Gierke * @author Jens Schauder + * @author Emanuel Trandafir */ public class SimpleEntityPathResolver implements EntityPathResolver { @@ -71,6 +72,7 @@ public EntityPath createPath(Class domainClass) { Class pathClass = ClassUtils.forName(pathClassName, domainClass.getClassLoader()); return getStaticFieldOfType(pathClass)// + .or(() -> getFieldForScalaObject(domainClass, pathClassName))// .map(it -> (EntityPath) ReflectionUtils.getField(it, null))// .orElseThrow(() -> new IllegalStateException(String.format(NO_FIELD_FOUND_TEMPLATE, pathClass))); @@ -80,6 +82,26 @@ public EntityPath createPath(Class domainClass) { } } + /** + * Resolves the static field of the given type inside the specified domain class. Useful for handling Scala-generated + * QueryDSL path classes. + * + * @param domainClass The domain class for which the static field needs to be resolved. + * @param javaPathClassName The Java path class name without the "$" suffix. + * @return + */ + private Optional getFieldForScalaObject(Class domainClass, String javaPathClassName) { + try { + + Class scalaPathClass = ClassUtils.forName(javaPathClassName + "$", domainClass.getClassLoader()); + return getStaticFieldOfType(scalaPathClass); + + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException( + String.format(NO_CLASS_FOUND_TEMPLATE, javaPathClassName + "$", domainClass.getName()), e); + } + } + /** * Returns the first static field of the given type inside the given type. *