user3475175
user3475175

Reputation: 83

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

Upvotes: 1

Views: 1276

Answers (1)

pratim_b
pratim_b

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

Related Questions