Reputation: 83
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
Upvotes: 1
Views: 1276
Reputation: 1200
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"));
Upvotes: 1