-->
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: one-to-many xml mapping (no pojos)
PostPosted: Wed Dec 17, 2008 1:34 pm 
Newbie

Joined: Wed Dec 17, 2008 12:59 pm
Posts: 1
Hi,

I am working on a project which involves translating a set of DTD's into hibernate mappings, then using the mappings to create DB2 tables and load in data from some large XML files.

I was inspired to use hibernate after learning that you could go straight from XML->DB without the need for POJOs. This tutorial helped:
http://javaboutique.internet.com/tutorials/mapping/

So far, everything has been working well. I am able to map simple XML elements and attributes without a problem.

However, I am now up against a problem that I thought would be simple. Namely - how do you map a PCDATA element which occurs multiple times in a parent element?

On other words, I would like to make this:

Code:
<Address primary="true">
   <AddressLine>6126</AddressLine>
   <AddressLine>Crossroads Lane</AddressLine>
   <AddressLine>fifth line</AddressLine>
   <City>Los Angeles</City>
   <State>California</State>
   <ZipCode>91608</ZipCode>
   <Country>US</Country>
</Address>


into these tables:

ADDRESS (one)
-----------------
id
City
State
ZipCode
Country

ADDRLINE table (many)
-----------------
id
AddressLine
ADDRESS_ID (points back to "id" within Address table)

I have tried the following in my mapping:

Code:
<class entity-name="Address" node="Address" table="WORKHEA.ADDRESS">
<id name="id" type="int"  column="id" length="6">
<generator class="native"/>   
</id>
<property name="primary" column="PRIMADDRESS"  node="@primary" type="boolean" length="5"/>

<set name="AddressLine" table="WORKHEA.ADDRLINE" inverse="true">
        <key column="ADDRESS_ID"/>
        <one-to-many entity-name="AddressLine"
         embed-xml="false"
         node="AddressLine"/>
</set>
<property name="City" column="CITY"  node="City" type="string" length="128"/>
<property name="State" column="STATE"  node="State" type="string" length="128"/>
<property name="ZipCode" column="ZIPCODE"  node="ZipCode" type="string" length="40"/>
<property name="Country" column="COUNTRY"  node="Country" type="string" length="128"/>
</class>


This creates the tables. However nothing is inserted into the ADDRLINE table.

This was my other attempt:

Code:
<class entity-name="Address" node="Address" table="WORKHEA.ADDRESS">
<id name="id" type="int"  column="id" length="6">
<generator class="native"/>   
</id>
<property name="primary" column="PRIMADDRESS"  node="@primary" type="boolean" length="5"/>
<property name="City" column="CITY"  node="City" type="string" length="128"/>
<property name="State" column="STATE"  node="State" type="string" length="128"/>
<property name="ZipCode" column="ZIPCODE"  node="ZipCode" type="string" length="40"/>
<property name="Country" column="COUNTRY"  node="Country" type="string" length="128"/>
</class>

<class entity-name="AddressLine" node="AddressLine" table="WORKHEA.ADDRLINE">
<id name="id" type="int"  column="id" length="6">
<generator class="native"/>   
</id>
<property name="AddressLine" column="ADDRLINE"  node="AddressLine" type="string" length="50"/>
<many-to-one name="Address"
            column="ADDRESS_ID"
            node="Address"   
            entity-name="Address"/>
</class>


Here, the tables are created. The correct amount of ADDRLINE records are created (corresponding to the XML doc), however they contain nulls in the ADDRLINE and ADDRESS_ID fields.

Is there anyone who can help me to do a simple many-to-one (or is it one-to-many?) relationship without the use of POJO's?

thanks,

Heather Buch

_________________
Life is sad
Life is a bust.
All ya can do.
Is do what you must.
-Bob Dylan


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.