Scenario:
borak wrote:
Step 1. Client makes a request to server to send all x'S
Step 2. Server queries and send x's
Step 3. Client unmarshal's response and get x's that server sent (new instances by List xs = (List) unmarshall(response); )
Step 4. I created new y object instance of Y and choose one of the x to make y.setX(x) in client side
Step 5. I send this y to server to save it by session.save()
( in mapping many-to-one name= "x" class = "X" column = "X_ID" )
Hibernate gives me: Save the transient instance before .... exception
I say ok; and I call session.saveOrUpdateCopy(x) before session.save(y).
In my understanding of saveOrUpdateCopy(x) :
Hibernate will look for the x instance with the same identifier value in the session, if founds he calls update, since no changes made to x in the client side, then nothing to be updated rather than the "user" instance loaded instead of the "server" instance with the same identifier . Then save(y) can move on correctly since its x object is in the session anymore. But it can not since hibernate throws now
another exception for saveOrrUpdateCopy(x) : NonUniqueObject exception....
What am I doing wrong? (If there is a simplier way for that scenario I am listening...)