如果我有2个参数username
和projectname
,如何查询特定项目?特别是,以下查询出了什么问题?
class Person {
private String name;
private List<Project> projects;
}
class Project {
private String projectname;
}
查询:
SELECT Project FROM Person p WHERE p.name := username AND p.projects.projectname =: projectname
结果:
illegal attempt to dereference collection [person0_.name.projects] with element property reference [projectname]
答案 0 :(得分:1)
因为您正在收集pojo的操作,所以在对其进行操作之前,您必须急切地加载该集合。
尝试(没有测试)
SELECT Project FROM Person p left join fetch p.projects as projs WHERE
p.name := username AND projs.projectname =: projectname