Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

self referencing relationship - many selects from hibernate

 
Billy Vandory
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using JPA with hibernate as the provider. I've implemented an entity with a self referencing relationship in order to be
able to do nested categories. When I load the root node, hibernate generates one select for each entity in the tree in order
to load the children. Im beginning to think, by the very nature of this type of tree, that this is unavoidable. can someone confirm?

Here's the mapping:



and here's the query. I just query the root node. Maybe this part is wrong



Here's the data:



and here's what hibernate does.



Too many selects (1 per entity to load all the children)

So, am I doing something wrong?
 
Shannon McGee
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Billy,

Since they are all seperate entities, I dont think there is a way around that. However, hibernate should help reduce the impact of all the calls w/ the shared cache and connection pooling.

-Shannon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic