• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Lazy collection size  RSS feed

 
Ranch Hand
Posts: 198
1
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to tell hibernate engine to cache the sizes of the lazy collection so it doesn't need to hit the database when we do users.size() ?

Thanks
Sundar
 
Sheriff
Posts: 11604
178
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

meenakshi sundar wrote:is there a way to tell hibernate engine to cache the sizes of the lazy collection so it doesn't need to hit the database when we do users.size() ?


If you want a standard JPA solution, you'll probably need to create a NamedQueryIf you don't mind using a specific Hibernate solution, you can use this annotation @LazyCollection(LazyCollectionOption.EXTRA). Using this annotation you get "smart" collection behavior, i.e. some collection operations such as size(), contains(), get(), etc. do not trigger collection initialization.

You'll find more information here and here. And beware there seems to be a bug when using LazyCollectionOption.EXTRA in combination with @Where.

Hope it helps!
Kind regards,
Roel
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!