如果我有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]
最佳答案
由于您正在对pojo的集合进行操作,因此您必须热切加载该集合,然后再对其进行操作。
尝试(未测试)
SELECT Project FROM Person p left join fetch p.projects as projs WHERE
p.name := username AND projs.projectname =: projectname
请refer association joins in HQL
关于java - 如何从数据库中选择列表中的特定条目?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17363650/