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: Several foreign keys to the same table.
PostPosted: Tue Oct 23, 2007 1:03 pm 
Newbie

Joined: Tue Oct 23, 2007 12:41 pm
Posts: 1
Hi,
I'm new to Nhibernate and I have a question about mapping files.
I have a simple database in Mysql 5 with these innoDB tables.
City(id, name)
Trip(id, orig_city, dest_city)
Both orig_city and dest_city are foreign keys to the City table

If I want to use collections for the bags, what should I do?
Do I have to do this:
city.hbm.xml

Code:
<bag name="TripList1" inverse="true" lazy="true" >
<key column="orig_city" />
<one-to-many class="Trip" />
</bag>
<bag name="TripList2" inverse="true" lazy="true" >
<key column="dest_city" />
<one-to-many class="Trip" />
</bag>


trip.hbm.xml
Code:
<many-to-one name="OrigCity" column="orig_city" class="City" />
<many-to-one name="DestCity" column="dest_city" class="City" />


and then do everything twice in the city.cs (members, property, add )?

Thanks,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 4:17 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
The city class only needs to be defined once with two collections; TripList1 and TripList2.

Symon.


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.