Joined: Sun Feb 06, 2005 6:48 pm Posts: 2 Location: Vancouver, EH
|
Hi,
I am new to Hibernate but loving it so far. I have found a couple of cases where I am not able (so far) to get hibernate to map the db to the object model I am trying to use. I have a couple of work arounds figured out, but I am hoping someone can offer a more elegant solution.
An example of the problem is our customer phone data. Currently in our database we have Customer table and a CustomerPhones table. The CustomerPhones table has a foreign key relationship to the customer table and is used to store both home and work phone numbers. The type of phone number (work/home) is identified by a column called phoneType in the CustomerPhones table.
Tables look like
CUSTOMER
customerId
name
addresss
....
CUSTOMER_PHONE
id
customerId
phoneType <== 0=home, 1=work
phoneNumber
I would like to make this transparent to the object model that I am trying to implement so that my new Customer object will have either
1. References to a home and work phone number
ie I can do stuff like
customer.getHomePhone().getNumber();
customer.getWorkPhone().getNumber();
or even better
2. Have the strings automatically loaded into the customer object
customer..getHomeNumber();
customer..getPhoneNumber();
What I would like to do is somewhere in the mapping document I would define the fact that the homePhone number has type 0 and the workPhone has type 1 and hibernate would automatically load the correct property for both the home and work phone.
Hope that makes sense
Daryl
|
|