posted 20 years ago
I can't help directly with your array issue. The few associations I have in my model are bidirectional one-to-many inverse relationships using Sets.
However, I can give you another option that will also solve a performace problem you'll find if the size of your tree gets large enough (50-100 items). The problem is that to load a tree you have to load the root item (Q1), then all of its children (Q2), then for each child you must load its children (Q3,4,5,...,n), and so on down the tree until each leaf is found. This results in a query for each item.
One way to solve this problem is to load and build the tree in code. First, add a new column to the table: root_id. It should hold the ID of the root item for the tree. To load a tree, load all items with the desired root_id. To build it, simply insert the items into the tree one-at-a-time.
Reducing n queries for an n-item tree to 1 query will save you a considerable amount of time. Since you'll be managing the relationships in code, it would side-step the current issue you're having with Hibernate.