My Database is SQL Server 2005 and here is how I have achieved.
Code:
Session session = somehow get session.
Criteria criteria = session.createCriteria(TaskTypeFunction.class,
"classone").setProjection(
Projections.projectionList().add(
Projections.property("name").as("test")));
SQL output
Hibernate: select this_.DISPLAY_NAME as y0_ from tbl_TASK_TYPE_FUNCTION this_
List<String> objects were returned.
Now Group by Name:-
Code:
Session session = somehow get session
Criteria criteria = session.createCriteria(TaskTypeFunction.class,
"classone").setProjection(
Projections.projectionList()
//.add(
//Projections.property("name").as("test")));
.add(
Projections.groupProperty("name")));
Hibernate: select this_.DISPLAY_NAME as y0_ from tbl_TASK_TYPE_FUNCTION this_ group by this_.DISPLAY_NAME
again List<String> objects are returned.
In your case you need not add the "name" in your projection. I guess If you have a group by in the HQL then Hibernate Adds it for you in the Projection also.
Hope this helps,
Latha.