I've run into a bit of a problem.
The project I'm working on needs to store very large hierarchical tree data. Often we'll need to retrieve an entire tree from our database. The way the program is set up uses the Adjacency List method for store trees (Records have parent columns to store their relationships). This seems to be the way that it's done it Hibernate, I haven't found an example of a parent-child relationship in any other way so far.
When attempting to retrieve an entire tree of several thousand entities, I've noticed that the system needs to make several thousand SQL queries as each record needs a query to check for children. Currently on our dataset, that can take about 20-30 minutes to retrieve a single tree. It's not really a fault of Hibernate, it would be just as slow in JDBC, but more of a database design issue I think.
I'd like to modify the database to use a Modified Preorder Tree Traversal (
http://www.sitepoint.com/print/hierarchical-data-database) to store and retrieve the data, as this would make retrieving a tree or any subtree performable with a single SQL query. Updates, Inserts, and Deletes would be a bit slower, but those are done gradually over time and I think not as much of an issue.
Does anyone know of a way to implement a Modified Preorder Tree Traversal in Hibernate? Am I looking at this incorrectly or perhaps using what comes with Hibernate in an inefficient manner? I've been scouring the 'net, but I haven't had much luck on this front. Any help would be greatly appreciated.