-->
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: Special collection mapping issue.
PostPosted: Thu Mar 02, 2006 6:37 pm 
Newbie

Joined: Thu Jan 26, 2006 4:22 pm
Posts: 6
I have an Employee Table that holds an AddressId column. This AddressId points to a LogicalId in an AddressTable. There will be multiple addresses with the same LogicalId in the Address Table( the Address table has EffectiveAt and Registered At columns too.).

I would like the Employee class to hold a (private) collection of Address instances. This collection should be fetched like this SELECT * FROM AddressTable WHERE LogicalId=Employee.AddressId. I can get this done by using a query allright, but I would like to get it done directly in the mapping file so that I can get cascading save to work.

(It seems to me that the Many To Many requires a relationship table and the One to Many requires my Addrerss table to know about my Employee.)

Can this be done?

Thanks in advance.

/Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 9:34 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yep. You need a one-to-many element in your Employee mapping:
Code:
<set name="Addresses">
  <key column="AddressId"/>
  <one-to-many class="Address" property-ref="LogicalId"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:19 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
property-ref in <one-to-many> isn't supported by NHibernate, I'm afraid...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 5:58 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Time to upgrade to java then!


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.