如何在hibernate条件查询中将投影字段设置为外键引用。例如,
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"));
例外:
org.hibernate.QueryException: could not resolve property: gradeId of: com.treamis.entity.UserEntity
答案 0 :(得分:1)
迟到的回答虽然:(想出相同的情景)
在这种情况下,您需要创建别名。
criteria.createAlias("gradeId", "gradeId");
criteria.setProjection(Projections.property("gradeId.gradeId"));