Hibernate Query API - 映射中键的属性标准
假设我有这样的模型:
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>
...
我如何使用 Hibernate Criteria 来列出已给定用户的项目? 我尝试这样做:
Criteria 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
任何帮助表示赞赏。
Let's say I have such model:
public class ProjectModel {
...
private Map<UserModel, ProjectUserRelations> usersRelations = new HashMap<UserModel, ProjectUserRelations>();
}
mapped in hbm like this:
...
<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>
...
How can I user Hibernate Criteria to list projects that have given user?
I tried with this:
Criteria hbCriteria = session.createCriteria(ProjectModel.class);
if(criteria.getUserId() != null) {
hbCriteria.createCriteria("usersRelations").add(Restrictions.eq("userId", criteria.getUserId()));
}
Of course user is mapped:
<class name="UserModel"
table="USER">
<id name="objectId" column="objectId" type="java.lang.Long">
</class>
When using current implementation a get:
org.hibernate.QueryException: could not resolve property: usersRelations.objectId of: ProjectModel
Any help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您想要做什么(在建模为多对多的地图的关键属性上设置标准)是否可以使用 hibernate criteria API 来实现。
你尝试过吗:
?
I am not sure what you are trying to do (setting up a criteria on key property of map that's modelled as many-to-many) is achievable using hibernate criteria API.
Have you tried:
?