-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Mapping in-memory tree (XOM, dom4j) to RDBMS
PostPosted: Tue Nov 16, 2004 6:18 am 
Newbie

Joined: Tue Nov 16, 2004 5:39 am
Posts: 3
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!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 7:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Hibernate cannot map the same class onto one of many tables based on some arbitrary criteria. What you need here is different classes representing these different mapping "Elements".

Sure, these could be Element subclasses if you want. You might also simply write domain objects and then use some form of XML binding to generate the DOM from that domain object graph.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 7:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
For mapping XML to a RDBMS I'd rather use a tool specialysing on this, not Hibernate. Hibernate is not exactly well suited to this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.