-->
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: Regards To Everyone:- Plz tell me hibernate query for count
PostPosted: Fri Apr 13, 2007 7:50 am 
Beginner
Beginner

Joined: Thu Apr 12, 2007 12:04 pm
Posts: 25
Location: Chennai
Hi And Regards,

I would like to know how to convert hibernate query for Count.

Example:- For query Like:---

select count(monthid) from month where name='"c1";

The Hibernate Query Is:---


Criteria crit1 = session.createCriteria(Honey1.class);
crit1.add(Restrictions.eq("name",userId));

crit1.setProjection(Projections.projectionList()
.add(Projections.count("monthid"))
)
.list();

List a=(List)crit1.list();


System.out.println("The Count is " +a);

Ans:== 1



The Same thing I would like to know for query Like:--

select count(*) from month where name='"c1";

Plz Do Help Me.
I Will Be So Greatful to You.

Thanks Lot.

_________________
I Really want to share my knowledge and learn from you all people specaily about Hibernate.. Thanks Lot


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 13, 2007 7:54 am 
Beginner
Beginner

Joined: Thu Apr 12, 2007 10:43 am
Posts: 21
Location: Brazil
Try doing it in HQL:

http://www.hibernate.org/hib_docs/v3/re ... ryhql.html

See section 14.7, 'Aggregate functions'. Cheers,
Roger


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.