I would like to implement the following SQL query with Hibernate Criteria:
select abc_id, count(*) from boa_rep_deed where sync_system = ? And hook_id = ? group by abc_id order by abc_id
what I have tried is this ...
List<teedObject> hytlow = null;
Criteria criteria = session.createCriteria(teedObject.class);
criteria.add(Restrictions.ne("abcID ", abcID));
criteria.add(Restrictions.eq("syncSystem", syncSystem));
criteria.add(Restrictions.eq("hookId", hookId));
hytlow = criteria.list();
Now my question is I have the corresponding pojo for this also as shown below..
class teedObject
{
private long abcID ;
private String syncSystem ;
private String hookId;
//and consisits other properties and setters and getters
}
Now I want my criteria to fetch only certain columns in order to make the object lighter so for that I have to use the projections in the criteria , can you please advise how to use projections in my case in order to fetch only certain coulmns , I have tried this..
Criteria cr = session.createCriteria(teedObject.class);
cr.add(Restrictions.eq("syncSystem", syncSystem));
cr.add(Restrictions.eq("hookId", hookId));
cr.addOrder(Order.asc("abcID"));
cr.add(Projections.groupProperty("abcID")));
cr.setProjection(Projections.rowCount());
hytlow = cr.list();
but it is throwing the exception as ..
java.lang.ClassCastException: org.hibernate.criterion.PropertyProjection
.. can you please advise have I implemented the projections in an correct manner