-->
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.  [ 6 posts ] 
Author Message
 Post subject: Person/addresses: parent-children or composite element?
PostPosted: Fri Nov 19, 2004 10:23 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
A Person object can have 0...many Addresses. The addresses are logically a property of the person. Do others normally map this kind of relationship as a standard parent-children (one to many) or as a composite element?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 10:28 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Both mappings imply a different lifecycle, also shared references (a single Address is associated with one/more than one Person) are different. It should be quite straightforward if you know your requirements.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 10:41 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
Each address is restricted to the one person, not shared. (Otherwise I'd settle for a straighforward many-to-many mapping). I'm trying to work out what the best policy is before going ahead and coding dozens of classes based on the decision...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 2:44 pm 
Regular
Regular

Joined: Fri Jul 16, 2004 3:04 pm
Posts: 52
Location: Wiltshire UK
I'd probably map the Address as a composite Object. There is a good example of this in Hibernate in Action & it explains why you would choose one over the other quite clearly. It is worth reading the book, it really explains a lot.


HTH
Paul :-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 2:57 pm 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
javacoda wrote:
I'd probably map the Address as a composite Object. There is a good example of this in Hibernate in Action & it explains why you would choose one over the other quite clearly. It is worth reading the book, it really explains a lot.


I will read the book and get the full explanation. What put me off the composite element idea was that it sees you have to specify the properties you are interested in mapping each time. That is, in my Customer mapping, I have a <composite-element> where I specify all the properties of the address and where they are to be mapped. Likewise in Organisation and wherever else. I'd clearly like to be able to do this just once.

Have I misunderstood the way this works?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 3:06 pm 
Regular
Regular

Joined: Fri Jul 16, 2004 3:04 pm
Posts: 52
Location: Wiltshire UK
Yes you would have to map them in each mapping file, but you would still only have one Address class.

If you use one-to-one relationships you would still have to map the relationship in each mapping file. I guess it depends how many classes that have Addresses you have. If you only have a handful of classes it is not that big a deal to map them as composites. It is probably more efficient though to have them as composites. I would really recommend reading the book before making a final decision.


Paul :-)


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