-->
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.  [ 3 posts ] 
Author Message
 Post subject: Persist elements of 2 different collections in the same tabl
PostPosted: Mon Dec 11, 2006 11:45 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
(using Hibernate 3.x)

Person and Building have multiple Addresses.
Person and Building are persisted in their own table. They do not share anything in common (separate class hierarchies).
I'd like to persist the Addresses in a single table, whether they are attached to a Person or a Building.

Code:
public class Person {
   ...
  Collection<Address> addresses;
   ...
}

public class Building {
   ...
  Collection<Address> addresses;
   ...
}

In addition, the Address's lifecycle is bounded to the one of its owner, ie. Person's addresses should be deleted when the Person is deleted.
In other words, Addresses are not shared between different entities.

I have tried many different mapping strategies with no (real) success... Hibernate offers so many options since the 3.x series - I'm getting lost.
Can someone please help me on this subject ?

Thx

/bertrand


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 11:53 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
What about table-per-class-hierarchy for Addresses? For example, you can create abstract class Address with two subclasses, PersonAddress and BuildingAddress, each mapped to the same table with some discriminator value.

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 11:59 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
lester wrote:
What about table-per-class-hierarchy for Addresses? For example, you can create abstract class Address with two subclasses, PersonAddress and BuildingAddress, each mapped to the same table with some discriminator value.


I understand your proposition, unfortunately, for many different reasons, we don't want to specialize the Address class only to be able to persist it... Besides this mapping problem, nothing else would differentiate a BuildingAddress from a PersonAddress.

I'd like somehow to consider this semantic has being part of the link Person-Address or Building-Address, not within Address itself.

See what I mean ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.