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: XML Mapping when a linked (N-To-N) table is used.
PostPosted: Tue Apr 07, 2009 11:03 am 
Newbie

Joined: Fri Apr 03, 2009 9:40 am
Posts: 10
I have 3 tables.

1. Person
2. PersonToAddress (columns PersonId, AddressId and AddressType)
3. Address

PersonToAddress is a link table between Person and Address. The PersonToAddress table does not exist due to a many to many relationship, but instead it allows both a home address and alternative address to be stored alongside a person entry.

In my C# entity Person I have a property of type Address. However, I’m struggling with the XML mappings.

I can get things to sort of work using a ‘bag’ but this is not what I want. In our data model Person maps one to one to address (and vice versa). So, what should the XML mapping look like?

Apologies in advance – I’m very new to NHibernate.

Cheers FlyTVR.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 12:25 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Is home and alternative address mutually exclusiv ? Then you can use a one-to-one association between Person and PersonToAddress. If not, you need the bag. Or do you have two properties on Person, one for the home address and a second one for the optional alternative address ? In that case you can try two many-to-one associations from Person to PersonToAddress, each with a "where" clause in the mapping, which contains the constraint for the address type.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 07, 2009 6:17 pm 
Newbie

Joined: Fri Apr 03, 2009 9:40 am
Posts: 10
wolli wrote:
Is home and alternative address mutually exclusiv ? Then you can use a one-to-one association between Person and PersonToAddress. If not, you need the bag. Or do you have two properties on Person, one for the home address and a second one for the optional alternative address ? In that case you can try two many-to-one associations from Person to PersonToAddress, each with a "where" clause in the mapping, which contains the constraint for the address type.


I have two properties on the Person entity - HomeAddress and AlternativeAddress. Using two many-to-one associations from Person to PersonToAddress - what would the mapping look like?

Cheers.

FlyTVR


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 08, 2009 2:10 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Just checked the many-to-one. It has not "where" attribute, so my idea does not work. But in that case, I suggest you use a normal many-to-many association. You can map to a private filed/property and define two properties which retrieve the correct address from the collection.

Code:
private IList<PersonToAddress> addresses;

public Address HomeAddress { get {
     return ... find home address in list ...; } }

public Address AlternativeAddress { get {
     return ... find alternative address in list ...; } }

_________________
--Wolfgang


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.