aspose file tools*
The moose likes Object Relational Mapping and the fly likes self referencing relationship - many selects from hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "self referencing relationship - many selects from hibernate" Watch "self referencing relationship - many selects from hibernate" New topic
Author

self referencing relationship - many selects from hibernate

Billy Vandory
Ranch Hand

Joined: Mar 23, 2010
Posts: 57
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

Joined: Oct 01, 2009
Posts: 18
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: self referencing relationship - many selects from hibernate
 
Similar Threads
Many-To-One mapping in hibernate using annotations
@PrimaryKeyJoinColumn with bidirectional @OneToOne relationship and @Id
hibernate get parent based on children
Stuck on manyToMany association
Hibernate 3.3.1 - Delete doesn't work