假设我有这样的模型:
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 列出已给用户的项目?我试过这个:
标准 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
任何帮助表示赞赏。