Hi,
I have an EmailMessage class which has its own unique key.
Each EmailMessage can be associated with TWO EmailAddress: emailAddressFrom and emailAddressTo
Each EmailAddress is associated with the owner's name.
Example table contents:
EmailMessage Table
---------------
id | email_address_from | email_address_to | message
1 |
bob@test.com |
sid@test.com | Hi Sid, See you at lunch, Bob
2 |
sid@test.com |
bob@test.com | Bob, See you at 12, Cheers Sid
3 |
sid@test.com |
sid@test.com | I'm emailing myself!
Each entry in email_address_from and email_address_to must exist in EmailAddress Table.
EmailAddress Table
---------------
email_address | name
bob@test.com | Bob
sid@test.com | Sid
Each entry in email_address column must be unique.
(I do not need to be able to get back from email_address in EmailAddress Table to EmailMessage).
I cannot work out the required mappings to get this to work... I've tried one-to-one and property-ref, many-to-one with unique="true" e.t.c., but I've not got anything working (so I've not posted my mapping file which is a mess!).
If anyone could help me write this mapping file for these two classes that'd be much appreciated.
Code:
public class EmailMessage {
private long id;
private EmailAddress emailAddressFrom;
private EmailAddress emailAddressTo;
private String message;
public EmailMessage() {
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public EmailAddress getEmailAddressFrom() {
return emailAddressFrom;
}
public void setEmailAddressFrom(EmailAddress emailAddressFrom) {
this.emailAddressFrom = emailAddressFrom;
}
public EmailAddress getEmailAddressTo() {
return emailAddressTo;
}
public void setEmailAddressTo(EmailAddress emailAddressTo) {
this.emailAddressTo = emailAddressTo;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
Code:
public class EmailAddress {
private String emailAddress;
private String name;
private EmailMessage emailMessage;
public EmailAddress() {
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setEmailMessage(EmailMessage emailMessage) {
this.emailMessage = emailMessage;
}
public EmailMessage getEmailMessage() {
return emailMessage;
}
}