-->
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.  [ 1 post ] 
Author Message
 Post subject: Saving one XML documento into multiple tables
PostPosted: Fri Feb 19, 2010 7:50 pm 
Newbie

Joined: Fri Feb 19, 2010 7:33 pm
Posts: 1
Hello.
I have an XML I need to persist. The root element has several attributes (master values) and several children (detail rows), but those are in an encapsulating tag.
So, I need to save that into master-detail tables.

e.g.
Code:
<master attr1="val1" attr2="val2">
  <children>
    <detail dAttr1="dVal1" dAttr2="dVal2">
    <detail dAttr1="dVal1" dAttr2="dVal2">
    <detail dAttr1="dVal1" dAttr2="dVal2">
    <detail dAttr1="dVal1" dAttr2="dVal2">
  </children>
</master>


And I need to save that into two tables:
Master with fields: Id, attr1, attr2
Detail with fields: Id, dAttr1, dAttr2, fKey

Where fKey is the reference to its parent row in Master.

I created two mapping files, for master and detail. Problem is I not sure how to indicate in the master the relationship with Detail, so it will save both when parsing the XML. No mention the Children element in the middle.

I tried something like

Code:
   <class entity-name="Master" node="master"
           table="Master" catalog="MyDB">
        <id name="Id" type="java.lang.Long">
            <column name="Id" />
            <generator class="identity" />
        </id>
        <property name="attr1" node="@attr1" type="string">
            <column name="attr1" length="6" not-null="true" />
        </property>
        <property name="attr2" node="@attr2" type="string">
            <column name="attr2" length="6" not-null="true" />
        </property>
        <component name="children" node="children">
            <list name="detail" table="Something">
                <key column="Id" unique="true"></key>
                <list-index column="ID_IDX"></list-index>
                <one-to-many entity-name="Detail"></one-to-many>
            </list>
        </component>
    </class>


Code:
  <class entity-name="Detail" node="detail"
           table="Detail" catalog="MyDB">
        <id name="Id" type="java.lang.Long">
            <column name="Id" />
            <generator class="identity" />
        </id>
        <property name="dAttr1" node="@dAttr1" type="string">
            <column name="dAttr1" length="6" not-null="true" />
        </property>
        <property name="dAttr2" node="@dAttr2" type="string">
            <column name="dAttr2" length="6" not-null="true" />
        </property>
    </class>


But when I do in Code
Code:
   List list = document.selectNodes("//master");
            Iterator iter = list.iterator();
            while (iter.hasNext()) {
                Object master= iter.next();
                dom4jSession.save("Master", master);
            }

It saves only to master, and nothing to detail.

Someone can help me identify what is wrong?

Thanks a lot.


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

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.