I am trying to persist a graph of objects that are laid out as follows:
A have a Tree (T) object that owns a collection of Nodes (N). Each node has a collection of child nodes and a reference to a parent node (these are non-containment relationships) forming an hierarchy of nodes.
I basically want to load T and in one swoop all N with N.parent and N.childNodes properly populated forming a tree in memory (as opposed to loading T then the root N then the level 2 Ns, then etc etc)
The problem is that I am trying to merge this graph and even if it is an entirely new graph and doesnt exist in the db I still get an EntityNotFoundException.
After debugging for a bit I noticed that Hibernate is merging T, which in turn is merging T.nodes. Then it tries to merge each Node in T.nodes but barfs when trying to copy references from a Node that has a ref to another one that hasnt been yet copied and its not in the internal cache.
Am I trying to do something that is not supported in Hibernate or should I customize my mapping in such a way that I am able to merge T without issues?
thanks,
-- yuri
|