javamona wrote:
The semantics used by Hibernate is quite correct. Within the session there should be only one unique instance of an entity. You are a Person and you're are also a Customer but there's still only one instance of you at any time.
So the solution would be to ensure that the Hibernate session only sees one instance at any time.
a. Retrieve the Person using a query, then copy the properties to the newly created Customer object then save.
OR
b. Load the Person, close the session, create a Customer using the person properties or with a method on the Person class
Customer becomeCustomer();
then when the user seeks to become a Customer open a session and save.
Thank you very much. I tried solutions that you mentioned above and still got problems. Let's overview the actions perfomed by Hibernate when creating a new instance of a child class: Hibernate inserts all property values inherited from the parent class into the parent class table and then inserts other property values owned by the child classs into the child class table.
That means if we copy properties of an EXISTING Person object to a new Customer object in a suitable way (e.g. close the session and create) and successfully create the Costomer object with the EXISTING Person object, a duplicated Person object will also be created. I've tried the above solutions and the problem did happen.
I am completed confused about this and doubting the sematics used by Hibernate is accurate enough.
Welcome any suggetions. Thanks.
Cheers,
James