-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one
PostPosted: Tue Feb 23, 2010 1:27 pm 
Newbie

Joined: Tue Feb 23, 2010 1:12 pm
Posts: 2
hello~
i'm having trouble trying to setup a many-to-one relationship between two tables in my database. my mapping is basically setup like this:

Code:
<class name="ForeignTbl" table="foreign_tbl">
   <id name="foreignID" column="foreign_id" type="integer">
      <generator class="native">
   </id>

   <property name="foreignKeyToOtherTbl" column="foreign_key_to_other_table" type="integer" not-null="true" />

   <many-to-one name="PrimaryTbl" property-ref="foreignKeyToOtherTbl" column="primaryID" class="primaryclass" not-null="true" lazy="false" />
</class>

i thought this would be fairly straight-forward with the many-to-one describing the relationship between the "many" table described here and the "one" table with the property-ref describing the column (or property) that relates the "many" table to the "one" table and the column attribute describing the column in the "one" table being related to...

is this not correct?


Top
 Profile  
 
 Post subject: Re: many-to-one
PostPosted: Wed Feb 24, 2010 5:33 pm 
Newbie

Joined: Tue Feb 23, 2010 1:12 pm
Posts: 2
i figured it out...it needs to be the foreign-key attribute not the property-ref...not sure why i didn't see that one in the list. so in case anyone else is looking for an answer it should look like this:

Code:
<many-to-one name="nameOfOneObjectInManyClass" column="foreignKeyFieldNameInManyTable" foreign-key="primaryKeyFieldInOneTable" class="pathToOneClass" />


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