Hi,
I'm attempting to set up the storage for a set of heirarchic objects, and have found myself a little confused with the syntax for the hibernate mapping.
Suppose I have an object Node, which can contain multiple child Node objects and also a single parent Node object, plus some other, random properties. How is it best to go about storing this using Hibernate.
----
public class Node
{
private Long id;
private String value;
private Set<Node> children;
private Node parent;
}
----
At the moment, I've been working with a single "nodes" table, and a "parent2child" table as my storage model in mind. The value of the node is trivial, but It's the relationships between the nodes that are confusing me. For the children I have specified:
<set name="children" table="parent2child">
<key column="id"/>
<many-to-many column="id" class="Node" />
</set>
Which looks like it might work, but suggests to me that it might try and give the table two "id" columns.
But for the parent I'm quite stumped. Some sort of use of the <one-to-one> mapping is probably appropriate.
I am very new to Hibernate, so if this is an obvious problem, apologies.
Cheers,
Richard
|