Hi,
I have problem with combining Restrictions and Projections on DetachedCriteria. If I use Restriction or Projections separately the program works fine. How can I combine those two together? Here is my sql: "select cTopic.topic ,SUM(cTopic.records) as records from Topics cTopic where cTopic.id=? and cTopic.active =? GROUP BY cTopic.topic order by cTopic.orderTopics
The following Java codes work fine without using group by (setProjection)
DetachedCriteria criteria = DetachedCriteria.forClass(Coursetopics.class); criteria.add(Restrictions.eq("active","Y")); criteria.add(Restrictions.eq("id.courseid",Id)));
List sumList = (List)hibernateTemplate.findByCriteria(criteria);
if I add following line of code before last line(List) the program does not work properly.
criteria.setProjection(Projections.projectionList(). add( Projections.sum("records")). add( Projections.groupProperty("topic") ));
MK
|