I want to write following sql using projection in hibernate
SELECT id, name, MAX(ver)
FROM bizterm
WHERE name ILIKE '%AB%'
GROUP BY name, id order by name asc
I have written following code
Session session=sessionFactory.getCurrentSession();
Criteria criteria=session.createCriteria(BizTerm.class);
criteria.add(Restrictions.ilike("name", searchString,MatchMode.ANYWHERE));
criteria.addOrder(Order.asc("name"));
ProjectionList projList=Projections.projectionList();
projList.add(Projections.max("ver"));
projList.add(Projections.groupProperty("id"));
projList.add(Projections.groupProperty("name"));
criteria.setProjection(projList);
In the table id,ver are the PKEY.
This query is running fine but in result I am getting value of only 3 column that is ver,id,name that too as Object,There are other column like status,level in the BizTerm table those value are not getting returned in the result set. How can I get those using projection? I tried projList.add(Projections.property("status")); but its not working.
I want this query to be executed
SELECT id, name,status,level MAX(ver)
FROM bizterm
WHERE name ILIKE '%AB%'
GROUP BY name, id order by name asc using projection in hibernate
Did like this..now its working no error
Note: I dont need maximum of status,levels,createDate,modifyDate but if I am not writing them inside max function then getting following error
with max function everything seems to be fine