-->
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: Is it possible to get count from a sessionFactory query
PostPosted: Fri Nov 19, 2010 2:05 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
I have the following query
sessionFactory.getCurrentSession().createQuery("from Employee).list();

Currently, the query takes a long time since it eagar fetched many associations (which is needed since data needs to be passed to another system). This time delay is alright for most of the cases but there are situations where I need to know if there are any records present and not get the whole data.... Something like a count.

Can I use the sessionFactory.getCurrentSession() to just get the count.


Top
 Profile  
 
 Post subject: Re: Is it possible to get count from a sessionFactory query
PostPosted: Fri Nov 19, 2010 2:46 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Yes: select count(e) from Employee e. The result is returned as a Long object.

See http://docs.jboss.org/hibernate/core/3. ... ggregation for more examples.


Top
 Profile  
 
 Post subject: Re: Is it possible to get count from a sessionFactory query
PostPosted: Fri Nov 19, 2010 9:07 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
Thanks, I amn't in front of my machine now. Will check this out soon.

Are you sure that it won't eagar fetch the associations.


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.