-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: NonUniqueObjectException made me crazy
PostPosted: Thu Jan 13, 2005 10:22 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
Hi all,
I am using hibernate on a client-server application, where client request for server by invoking a command and according to the command, the server calls hibernate to return the data as a response for the client.

The scenario:
client requested x's from server
server gets request, call hibernate session.find(request arguments)
and returns the list of x's.
then the client modify a x object and send another request to server to update the x,
then server throws NonUniqueObjectException a different object with the identifier already associated with the session....

I think hibernate is doing absolutely great work,
, but I wonder how and why why why why it made such a simple update that much complicated??


I know why hibernate throws that exception
there are 2 instances of Class X the same identifier-values.
in the session.

Should I override the equals method to force hibernate to understand that if 2 object have same PK(!!!!!) then they are same objects or what can I do as a better solution?

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 11:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
use saveOrUpdateCopy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 12:20 pm 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
but be careful with "saveOrUpdateCopy" ... in HB2 it doesn't work with Collections ...

In 'every' other case it works perfectly for me ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 15, 2005 1:57 pm 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I updated Hibernate to 3.0
I used saveOrUpdateCopy of classic session (it is depreciated there?) but it still gives the same error!
In that case why doesnt saveOrUpdateCopy work correctly?

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...)

Note: Identifier values of instances are Long
Class X : Long id,...

Can we say that hibernate is not a good choice for a client-server application?

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 15, 2005 3:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use the search engine.

http://opensource.atlassian.com/project ... se/HB-1202


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 16, 2005 7:59 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
my problem is not the saveOrUpdateCopy with cascade throw NonUniqueObjectException.
Did u read the scenario I sent?

_________________
-developer


Top
 Profile  
 
 Post subject: client-server application
PostPosted: Sun Jan 16, 2005 8:21 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
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...)


_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 16, 2005 10:17 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I cant still solve the problem...
I need help for the scenario above.

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 16, 2005 2:05 pm 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I did.
saveOrUpdateCopy works perfect!
Hibernate works perfect!

_________________
-developer


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.