Hi,
I'm fairly new to Hibernate so I wanted to ask the great Hibernate community to give me some pointers, thoughts or design patterns how to map an existing in-memory tree (e.g. XOM or dom4j) to RDBMS with Hibernate.
Mostly all nodes in that tree are instantiated with the same class ("Element") and could be distinguished by an attribute typ. Every node has a list of its children. Futhermore, these node types have to be stored in different db-tables.
Example: A car consists of severel parts (tires, seats, doors .. ) and is represented as a XML-file.
<cars>
<car name="car1">
<tires>
<tyre> One </tyre>
<tyre> Two </tyre>
<tyre> Three </tyre>
<tyre> Four </tyre>
</tires>
<seats>
...
</seats>
...
</car>
...
</cars>
Unfortunately during some business logic it has to be respresented as in-memory tree. So, I've parsed the XML file and generated a XOM (or dom4j) tree.
But how do I create a Hibernate mapping for this in-memory tree with different db-tables (Car, Tyre, Seat..) and read it again out of it in the same structure where all nodes have the same POJO "Element"?
Or is it easier to subclass the "Element"-class and create required real classes like "Car", "Tyre", "Seat".. and create a Hibernate mapping with them? But how do I reconstruct the tree-structure with that?
Thank you all and kind reagards!
|