• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to get count from a sessionFactory query

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Have a look at Projections.

Personally, if you don't always need to eagerly fetch data (which is your case) I would leave things mapped as lazy and eagerly fetch where required.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic