0

username如果我有 2 个参数和,如何查询特定项目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]
4

1 回答 1

1

由于您正在对 pojo 的集合进行操作,因此您必须在对其进行操作之前急切地加载集合。

试试(没测试)

SELECT Project FROM Person p left join fetch p.projects as projs WHERE
                        p.name := username AND  projs.projectname =: projectname

参考 HQL 中的关联联接

于 2013-06-28T11:34:57.930 回答