-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: DetachedCriteria adding Restrictions and Projections
PostPosted: Fri Apr 08, 2011 12:39 pm 
Newbie

Joined: Fri Apr 08, 2011 12:32 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.