问题
I have a set of classes that implements the same interface. For example:
public interface Employee{
private String name;
public void work();
public String getName();
}
@PersistenceCapable(detachable = "true")
public class Accountant implements Employee{
}
@PersistenceCapable(detachable = "true")
public class Secretary implements Employee{
}
And another class that holds the Employee implementations:
public class Department{
private ArrayList<Employee> employees;
public ArrayList<Employee> getEmployees();
}
I want to get a list of Department that has Employee named "Mary". How should I put my jdo query? Am I missing some annotation to the interface Employee?
I suspect the Q class generated is not correct. I got
public final SimplePath<java.util.ArrayList<Employee>>
in the generated Q class. Shouldn't it be ListPath
instead of SimplePath
?
回答1:
There are two issues here
Employee
is not recognized as an entity type, since it is not annotatedArrayList
is not a supported List type in Querydsl, only Collection interfaces are supported
Consider annotating Employee
and use List
instead of ArrayList
来源:https://stackoverflow.com/questions/20087378/how-querydsl-works-with-interface