• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

please help me avoid n+1 select hibernate

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using hibernate for persistance. All my entities most od the associations are lazy and by default collections are lazy. I also have lot of criteria queries and because of lazy mapping I always face n+1 problem. Suppose I have item and bids the famous example by default bids are lazy , so in a criteria query If I select Items and I also needs bids for each item in this case I end up with n+1 select please tell me how can I avoid n+1 using criteria ?

 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate is doing this behind the scenes for you, right? So, you're not doing multiple queries, but instead, somewhere in a place where you're not controlling program execution, these n+1 selects are happening, right?

Just confirm this for me so I have a clear picture of your problem.

-Cameron McKenzie
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you know you need the associated objects why not eagerly fetch them?
reply
    Bookmark Topic Watch Topic
  • New Topic