-->
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.  [ 2 posts ] 
Author Message
 Post subject: question about count in hibernate
PostPosted: Fri May 18, 2007 10:05 pm 
Newbie

Joined: Fri May 18, 2007 9:49 pm
Posts: 1
Hi all, I'm a newbie in hibernate. I have a question about how to use count() function in DetachedCriteria

Table schema as follow
Member Field plus
jacky aaa 10
jacky bbb 10

I would like to execute the following sql
Select field, count(plus) from transaction where member = ‘jacky’ group by field


How should I do in DetachedCriteria, pls help, thanks very much


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 19, 2007 3:56 pm 
Newbie

Joined: Tue Aug 29, 2006 10:56 am
Posts: 15
DetachedCriteria query = DetachedCriteria.forClass(Transaction.class);
query.setProjection( Projections.projectionList()
.add( Projections.count("plus"))
.add( Projections.groupProperty("field") )
);
query.add(Restrictions.eq("member", "jacky"));
Criteria c = query.getExecutableCriteria(session);
List result = c.list();


see also hibernate reference guide


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

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.