[英]Using Hibernate Criteria API, how to query for a subproperty of a property that exists only for certain property types
[英]Hibernate Query API - criteria on property of a key in map
假設我有這樣的模型:
public class ProjectModel {
...
private Map<UserModel, ProjectUserRelations> usersRelations = new HashMap<UserModel, ProjectUserRelations>();
}
像這樣在hbm中映射:
...
<map name="usersRelations" cascade="save-update" table="PROJECT_MEMBERS">
<key column="project_id" />
<map-key-many-to-many column="user_id" class="UserModel"/>
<many-to-many column="properties_id" class="ProjectUserRelations"/>
</map>
...
如何使用“休眠條件”列出已給用戶的項目? 我嘗試了這個:
條件hbCriteria = session.createCriteria(ProjectModel.class);
if(criteria.getUserId() != null) {
hbCriteria.createCriteria("usersRelations").add(Restrictions.eq("userId", criteria.getUserId()));
}
當然,用戶映射為:
<class name="UserModel"
table="USER">
<id name="objectId" column="objectId" type="java.lang.Long">
</class>
使用當前實現時,將獲得:
org.hibernate.QueryException: could not resolve property: usersRelations.objectId of: ProjectModel
任何幫助表示贊賞。
我不確定要使用休眠標准API來實現什么(在建模為多對多的地圖的關鍵屬性上設置標准)。
你有沒有嘗試過:
hbCriteria.createCriteria("usersRelations").add(Restrictions.eq("userModel.userId", criteria.getUserId()));
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.