-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping question
PostPosted: Wed Dec 05, 2007 3:14 pm 
Beginner
Beginner

Joined: Tue Nov 27, 2007 1:25 pm
Posts: 24
Situation:
A <-- link table AB --> B
A has IdentityA column as PK;
B has IdentityB column as PK;
AB contains FKs to both tables (IdentityA and IdentityB FKs).

In real case A is linked to B as 1:1, meaning that there is only one B related to A.

Is there a way to write such mapping file, so that A contained not the list of Bs, but just one reference to B (as using <many-to-one> mapping)?


Top
 Profile  
 
 Post subject: Re: Mapping question
PostPosted: Wed Dec 05, 2007 4:36 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
crash wrote:
Situation:
A <-- link table AB --> B
A has IdentityA column as PK;
B has IdentityB column as PK;
AB contains FKs to both tables (IdentityA and IdentityB FKs).

In real case A is linked to B as 1:1, meaning that there is only one B related to A.

Is there a way to write such mapping file, so that A contained not the list of Bs, but just one reference to B (as using <many-to-one> mapping)?


Yes you will need to use a join. It eventually should look something like:

Code:
<class name="A" ...>
  ....
  <join table="AB">
      <key name="IndentityA" unique="true"/>
     
      <many-to-one name="bPropertyInA" column="IndentityB" class="B" unique="true"/>
  </join>
  ...
</class>



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 3:27 am 
Beginner
Beginner

Joined: Tue Nov 27, 2007 1:25 pm
Posts: 24
Which version of NHibernate are you using? I can't seem to find the <join> tag..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 12:01 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
crash wrote:
Which version of NHibernate are you using? I can't seem to find the <join> tag..


My bad. I was thinking of hibernate for Java. However, I took a look at NHibernate documents and I couldn't find any one-to-one association with an association table, I took a fast look though. One-to-one associations with an association table are extremely rare anyways. One thing you can do is to define a view in your database so that it looks like a simple many-to-one and map the view instead of table. However, it might not be your choice if you need to update the data in that table too.

Farzad-


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