• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

n+1 solution, is it good , really ?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I have been reading Hibernate In Action book and a question comes to my mind .
This book suggests a solution to n+1 problem :
Make your default fetching strategy is lazy (at mapping level) then override it with eager fetching in code.
Well, it seems to me that this approach imposes extra load on the database and the application in overall.
Any clarfications ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is a good solution because when you have more than one colletion in a mapped object, you can only eager load one Collection. Each Use Case could need a different Collection eager loaded for performance. So it is better to set it to eager at time of creating the query. Also look at "subselect" for laxy loading, but when you access the Collection, it will run a single query to load the Collection, using the original first query as a subselect in that next query.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic