-->
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: Two components of one type in Parent class
PostPosted: Tue Jan 27, 2004 3:42 pm 
Newbie

Joined: Tue Jan 27, 2004 3:26 pm
Posts: 18
Hello,

I'm quite new to hibernate and have problems creating mapping for my legacy classes and schemas. Consider we have two classes: Person and Address. Person has (exactly) two types of addresses (livingAddress and correspondenceAddress), ie:

public class Person {
int id;
Address livingAddress;
Address correspondenceAddress;
}

I've association as below

PERSON (Id)
ADRESS (
Id PK,
PersonId FK,
AddressType -- 0 for livingAddress and
-- 1 for correspondence )

plus some trigger to ensure consistency (exactly two addresses for one person).

Is there possible to map this kind of assosiation in hibernate? I've tried one-to-many, but did not succeed. I don't now how to map Addresses of type 0 to livingAddress member, and 1 to correspondenceAddress. Any help would be appreciated.

Regards,
Artur


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2004 3:44 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Try a custom UserType.

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


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.