-->
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.  [ 5 posts ] 
Author Message
 Post subject: XML to POJO to DB
PostPosted: Fri Dec 09, 2005 1:00 pm 
Newbie

Joined: Fri Dec 09, 2005 12:53 pm
Posts: 3
Hibernate version:
3.0.5

I understand that Hibernate supports XML <-> DB and POJO <-> DB mappings, and I understand that is not a Java/XML binding framework. Still, I'm wondering if there is a way to do XML <-> POJO mapping, using the information in the mapping files, before persisting the POJOs to the DB?

Thanks for the great product.


Top
 Profile  
 
 Post subject: Elaboration
PostPosted: Fri Dec 09, 2005 4:40 pm 
Newbie

Joined: Fri Dec 09, 2005 12:53 pm
Posts: 3
I realize I didn't explain my question very well, so I will try to elaborate.

Hibernate's mapping definitions allow me to express the relationships between POJOs and the DB. So I can take POJOs and persist them to the DB using these mappings. I can also take DB records and load them into POJOs.

With Hibernate 3.0 I can take those same records and load them as XML using node attributes in the mapping definitions and/or persist and XML tree to the DB.

I'd like to take an XML tree and load it as POJOs, and/or take the POJOs and persist them to XML, without making all the objects go through the DB (for now). All the mapping information is there, so it seems like this could be done.

I've seen some similar posts through searching the archives, but have not found a solution. Gavin mentioned adding transform() functionality at some point earlier in the year ("it's trivial, just have to figure out the details").

If anyone has any ideas it would be much appreciated. I've reviewed all the relevant posts and documentation I could find.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:45 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
http://java.sun.com/j2se/1.4.2/docs/api ... coder.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 4:58 pm 
Newbie

Joined: Fri Dec 09, 2005 12:53 pm
Posts: 3
The mapping is a lot more complicated than XMLEncoder can accomodate. There is lots of nesting, something like below, where each element is its own object with several properties/attributes, and possibly referencing other objects in the tree.

<activity>
<sequencing>
<rules>
<rule>
<conditions>
<condition />
</conditions>
</rule>
<rule />
</rules>
<objectives>
<objective>
<objectiveMap />
</objective>
<objective />
</objectives>
</sequencing>
</activity>

I've tried Castor as well. Castor works fine for mapping the objects to the XML, but fails on mapping the XML to the objects. It seems like a Castor bug. Either way I haven't gotten any help from Castor's documentation or mailing lists.

I'd prefer to handle the who solution in Hibernate if possible, because I will be persisting some of the objects to the database later in the process.

Thank you.


Top
 Profile  
 
 Post subject: Good question
PostPosted: Sat Dec 10, 2005 11:58 pm 
Newbie

Joined: Sun Dec 04, 2005 2:24 pm
Posts: 9
I'm trying to figure out the same thing. I am using a "object_history" table to keep an audit trail of modifications to objects in my database. I use the same table for several classes of object. I have colums: objectClass, modificationDate, revisionId, objectXML

The 'objectXML' is generated using the code in chapter 19 of the Hibernate 3.0 manual
(http://www.hibernate.org/hib_docs/v3/re ... nipulation)

However I havn't figured out how to convert the XML (in a String) back to an object yet. A pointer to some example would be great -- I've googled around quite a bit and havn't found anything to date.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.