Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HIBERNATE- one-to-many mapping with different field names

 
George Tkebuchava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with persistent XML data rather then POJOs and trying to figure out how to get one-to-many mapping working when field names are different, in Table_1 its PERSON_ID and in Table_2 it's PER_PERSON_ID. DB is Oracle 8i.

Table_1
---------
PERSON_ID
LName
MNAME
FNAME

Table_2
---------
Addr_ID
PER_PERSON_ID
Address_1
Address_2

This is what I have and it worked for me in all the cases where field names match:

MasterNames:
<hibernate-mapping>
<class entity-name="MasterNames" node="row" schema="DBA" table="Table_1">
<id name="mstr" column="PERSON_ID" node="PersonID" type="string" length="13"/>
<set name="RelatedIncidents" node="Addrs">
<key column="PERSON_ID" not-null="true" update="false"/>
<one-to-many entity-name="Addresses"/>
</set>
</class>
</hibernate-mapping>

Addresses
<hibernate-mapping>
<class entity-name="Addresses" schema="DBA" table="Table_2" node="AddressNode" mutable="false">
<id name="PerID" column="Addr_ID" type="string" node="AddrID"/>
<property name="perID" column="PER_PERSON_ID" type="string" node="perID"/>
<property name="Addr" column="Address_1" type="string" node="Addr"/>
</class>
</hibernate-mapping>

I always get "field not found" error, as I should, since PERSON_ID doesn�t exist in Table_2.
Thank you in advance for your help.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"George TK",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with display names get deleted.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"<key column="PERSON_ID" not-null="true" update="false"/> "


Yep, the error you get is what you should have gotten. The key tag iin your set needs to point to the column that is the FK in table_2 which is not PERSON_ID, so what is it? I'll let you figure that out. What is the foreign key column in Table_2, that is what goes into your column attribute of the key tag.

Mark
 
George Tkebuchava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mark,
I tried using PER_PERSON_ID as a key value, however I still got �invalid column name� error. After your comment I checked the rest of the file and discovered that error was not related to PER_PERSON_ID.
Thanks again,
George
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by George Tkebuchava:
Thank you Mark,
I tried using PER_PERSON_ID as a key value, however I still got �invalid column name� error. After your comment I checked the rest of the file and discovered that error was not related to PER_PERSON_ID.
Thanks again,
George


Was it some other column that didn't exist in the table that you had a different attribute attempt to map to?

Mark
 
George Tkebuchava
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, in sort I specified field that didn't exist and was giving me issues all along. In addition since I�m new to hibernate I made some false assumptions and it all added up.
Thanks,
George
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic