Firstly, let me apologize if this is a stupid question, I have been through the FAQ's, I bought the recommended book Java Persistence with Hibernate.
It is such a simple question I feel so stupid, but it is annoying me so I though I would ask, an hope you don't all beat me up :)
So using the example in the book, with Billing_Details(superclass), Credit_card(subclass) and Bank_account(subclass).
I create an instance of credit_card, and an instance of bank_account
I persist credit_card
I then persist bank_account and get org.hibernate.NonUniqueObjectException
(in the same session)
Now maybe I missed something, and my understanding of hibernate is wrong.
What I thought would happen is it would save credit_card, thus creating the row in credit_card and billing_details.
Then when it went to persist bank_account, it would detect that the billing details already exist(because I just saved it with credit card), and just create the row in bank_account, thus linking it to the billing details.
I have tried this example using native hibernate, and the entity manager, and get the same issue. (hence why I think it is me)
With the entity manager I used em.persist and em.merge and got the same problem. (I tried .save and .saveorupdate in native)
(I am using postgress as the backend db, and all the latest release versions of hibernate stuff.)
So I am sorry, that it is just probably my understanding.
|