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
|