I have the following Domain objects:
-Person
-Address
- Mailing Address
- Home Address
Mailing address and Home address inherit from Address. A Person can only have one Mailing Address and only one Home Address. Hence, it makes sense for there to be a mapping that retrieves a Set of addresses. It also makes sense for there to be a mapping to get/set a Home Address since there is only one of them.
The addresses are all in the same table, hence I am using table per class hierarchy. The discriminator column is only used to mark what kind of address it is.
What is the best way of dealing with this?
My first approach is to have the somthing like the following:
Code:
public void setMailingAddress(MailingAddress address) {
Iterator iter = addresses.iterator();
while(iter.hasNext()){
Object temp = iter.next();
if(temp instanceof MailingAddress) then remove the address and replace it with the one passed in and then return from the method
}
add the address and return
}
Of course the getter would need to do similar logic.
This doesn't seem to be correct to me. Has anyone else delt with this?
thanks