简体   繁体   English

使用休眠条件将“投影”字段设置为休眠状态中的外键列

[英]Using Hibernate Criteria set Projection field as Foreign key column in the hibernate

How to set the projection filed as the foreign key reference in the hibernate criteria query.Example like, 如何在休眠条件查询中将投影字段设置为外键参考。示例如下,

 Criteria crt = s.createCriteria(UsersforGrades.class).createCriteria("id", "id1").createCriteria("id1.userId", "id2").add(Restrictions.eq("id2.userId", ue.getUserId()));
                ProjectionList proList = Projections.projectionList();
                proList.add(Projections.property("gradeId.gradeId"));

Exception: 例外:

org.hibernate.QueryException: could not resolve property: gradeId of: com.treamis.entity.UserEntity

Late answer although: (Came up with the same scenario) 较晚的答案是:(跟上相同的情况)

In such case you need to create alias. 在这种情况下,您需要创建别名。

criteria.createAlias("gradeId", "gradeId");
criteria.setProjection(Projections.property("gradeId.gradeId"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM