I am currently evalutating the possibility of using hibernate bridging between an old database schema and a newly developed java object model and I'm wondering if the following can be done in hibernate:
There is a table PERSON, holding simple person properties. To keep the column count manageable someone decided to create a new table PERSON_EXTRA that has a one-to-one relationship with person. The primary key in PERSON_EXTRA is PERSON_ID and also a foreign key refering to the PERSON table.
Now it happens to be so that some properties in PERSON_EXTRA groups logically into a class holding employment information in the java object model (Employment), and some properties groups logically into information about the current landlord of the person (Landlord).
I have created a one-to-one association between User <-> Employment and User <-> Landlord using the method decscribed in "One-to-one associations" / "Using a primary key association" on page 223 in "Hibernate in action" and it works great for reading data from the database.
When saving new data to the database however the insert of the Landlord data fails as a second insert with the same primary key into PERSON_EXTRA violates the uniqueness constraint of the primary key.
Is there a way of persuading hibernate to save both the new Landlord and Employment objects in the same PERSON_EXTRA row? Is there another smart way of achieving the same thing?
I hope someone has a solution to this problem, as hibernate seems great in so may ways and I'd love to use it, but changing the database schema is not an option for us unfortunately :/
|