-->
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: Many-to-one with different one types
PostPosted: Tue Dec 20, 2005 9:45 pm 
Beginner
Beginner

Joined: Tue Dec 20, 2005 9:40 pm
Posts: 20
I have an Address object. I would like to use this object to represent addresses in many different contexts. E.g. I would like to use to represent a customer's address, an order's address, a building's address, etc. However, since I have to make the association bi-directional, I'm afraid I'm going to have to subclass Address for each use. I.e. CustomerAddress: Address, OrderAddress: Address, etc. This is because each of the addresses need to contain a field which represents it's parent. I.e. CustomerAddress has to have a _customer property. Is there anyway of doing this without doing the subclassing? Or am I stuck doing the subclassing because of NHibernates bi-directionality requirement?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 12:40 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
Do you really need the association to be bidirectional (because its not a NH requirement)? If not, the solution is quite simple: don't let the Address table hold the foreign key to your Order, Customer tables, instead have each Customer, Company, Person, Order have a foregin key to your Address table.

The things become really complex if you need a bidirectional association: you will derive all your Company, Order, Person objects from a base class , let say ObjectWithAddress which defines the Address property. This case is covered in the Hibernate documentation when it discusses implicit polymorphism "8.1. The Three Strategies". Check the table per concrete subclass strategy.

Cheers,
Radu


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.