2013-06-28 63 views
0

如何查詢特定項目如果我有兩個參數usernameprojectname?特別是,以下查詢有什麼問題?如何從數據庫中選擇列表中的特定條目?

class Person { 
    private String name; 
    private List<Project> projects; 
} 

class Project { 
    private String projectname; 
} 

查詢:

​​

結果:

illegal attempt to dereference collection [person0_.name.projects] with element property reference [projectname] 

回答

1

,因爲你在你的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

相關問題