![](/img/trans.png)
[英]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.