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"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.