-->
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: Select multiple types in the same list...
PostPosted: Sat Aug 11, 2007 8:17 am 
Newbie

Joined: Sat Aug 11, 2007 7:55 am
Posts: 2
Hi guys,

I'm brand new to the forum, since I started using NHibernate yesterday, dropping out the ORM I used to develop for a while (which wasn't bad, but had not the community support (N)Hibernate has).

My question is about the procedure for writing an HBM mapping that makes me select multiple types in the same IList instance of a type, using some polymorphisms.
Something like:

Code:
public class Person {
    public long Id;

    public string FirstName;

    public string LastName;

    public IList Addresses;
}

public class Address {
    public long PersonId;

    public string Street;

    public string Number;

    public string City;

    public string State;

   public string Country;

   public string Zip;
}

public class WorkAddress : Address {
    public string OfficeNumber;
}


The result I would like to obtain is to select from the tables "Address" and "WorkAddress", all the instances related to the "PersonId" field specified.
My assumption was to use several <idbag> (one for each entity type to select) on the same field ("Addresses" in this case).

Could you please correct me if I'm wrong and eventually post me a valid HBM to achieve this result?

Thank you all!
Antonello


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 12, 2007 7:15 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
Hello,

I wonder if it wouldn't be easier to store your address and workaddress records in the same DB table, with one field differenciating both types.
In that case, you only need 1 mapping with a discriminator.

Your mapping will also contain an association 'many-to-one' to the Person class, to allow you to query the address of a given Person.

And/Or your Person class will contain a 'one-to-many' collection to Addresses, which will allow you to execute the inverse operation.

So, you can start by searching in the NHibernate reference documentation for the following keywords: 'discriminator' and 'many-to-one'. This will get you on track.

_________________
Please rate this post if it helped.

X.


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.