-->
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.  [ 4 posts ] 
Author Message
 Post subject: Cannot persist a detached object, please help
PostPosted: Sat Oct 17, 2009 2:01 pm 
Newbie

Joined: Sat Oct 17, 2009 1:48 pm
Posts: 9
I'm having a weird issue and Im sure its due to something stupid. I have an account object that I load via hibernate on sign on and store in servlet's HttpSession object and closing the sesison, thus making it detached. When I need the contents of this object modified I retrieve it from there, mutate it, and try to persist the changes but I cannot. if i use update() or lock() or replicate() I get a NonUniqueObjectException and I can guarantee that the session does not have anything in it, because I call this right after beginning the transaction. If I use merge() I get StaleObjectStateException. If I dont do anything and simply commit the transaction, the changes are not saved. What am I missing? Any tips? Thanks for your help.


Top
 Profile  
 
 Post subject: Re: Cannot persist a detached object, please help
PostPosted: Sun Oct 18, 2009 6:57 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
... I retrieve it from there, mutate it, and try to persist the changes but I cannot

wrong order, try it the simpler way:
1) retrieve it
2) begin transaction
3) merge it to session (reattach, use merge())
4) apply changes on the return value of merge()
5) commit transaction, close session

And please use the correct forum ;-)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Cannot persist a detached object, please help
PostPosted: Sun Oct 18, 2009 2:57 pm 
Newbie

Joined: Sat Oct 17, 2009 1:48 pm
Posts: 9
thanks for the reply.

I've tried it and it still gives me StaleObjectStateException. I think I figured what the problem is...in my account object I have a couple of country objects that are all the same. I think this is whats causing the NonUniqueObjectException...is it possible to associate the same object for 3 different properties with hibernate?


Top
 Profile  
 
 Post subject: Re: Cannot persist a detached object, please help
PostPosted: Sun Oct 18, 2009 5:10 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
sure it's possible;
I'm *guessing* as you didn't post a stacktrace and which versions you're using, but you might have a problem with the cascade policies.
Try to avoid automatic cascade, persist each one yourself (once per different primary key) and then associate them. This shouldn't be needed, but see if it helps.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.