-->
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.  [ 3 posts ] 
Author Message
 Post subject: Count rows using hibernate criteria API
PostPosted: Tue May 26, 2009 2:50 am 
Newbie

Joined: Tue Mar 13, 2007 9:53 am
Posts: 6
Location: HCL Technologies Ltd,N.M Road ,Chennai-600029,NungumBakam,India.
Hi,

Can some one help me to findout maximum number of rows in the list of specified values of a column.

Here is the seario.

Table( value , id)

Values (
value1,1
value1,1
value2,2
value2,2
value2,2
value2,2
}

Now I want to write a qurey to get maximum count in the table for the specified ids.
if I pass ids 1 and 2 the maximum count shoud be 4.

Please help me to write this using criteria API.

Thanks,
Naga.

_________________
Cheers,
Naga Nirangen , R.


Top
 Profile  
 
 Post subject: Re: Count rows using hibernate criteria API
PostPosted: Tue May 26, 2009 5:13 am 
Regular
Regular

Joined: Thu Apr 14, 2005 10:39 am
Posts: 115
See
Code:
org.hibernate.criterion.Projections
static Projection    rowCount()

in combination with
Code:
org.hibernate.Criteria
Criteria    setProjection(Projection projection)


E.g.
Code:
c.setProjection(Projections.projectionList().add(Projections.rowCount()));


Greetings Michael


Top
 Profile  
 
 Post subject: Re: Count rows using hibernate criteria API
PostPosted: Tue May 26, 2009 5:19 am 
Newbie

Joined: Tue Mar 13, 2007 9:53 am
Posts: 6
Location: HCL Technologies Ltd,N.M Road ,Chennai-600029,NungumBakam,India.
Thanks guys for all your replys.

It's working with projections.

_________________
Cheers,
Naga Nirangen , R.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.