-->
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.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.StaleObjectStateException
PostPosted: Thu Mar 18, 2010 1:30 pm 
Newbie

Joined: Thu Mar 18, 2010 1:20 pm
Posts: 4
Hi All,

I am working on a JSF/EJB3/Hibernate project. My issue is that I am trying to retrieve a persistent object but I need to change some of the fields before sending the object back to the UI. Again I do not want to persist the changes , they are temporary and only serve for displaying purposes. While doing that I get the following exception:

org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction.

From what I undstand this error is generated since the object is still connected to the persistent context. So I need to find a way to apply those changes without getting hibernate trying to persist them which results in the error I am getting.

Any replies are highly appreciated and please also let me know if I have misunderstood something about the framework.

Cheers.


Top
 Profile  
 
 Post subject: Re: org.hibernate.StaleObjectStateException
PostPosted: Fri Mar 19, 2010 6:41 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
For this purpose you must detach the object or set it to read-only:

detach:
Code:
session.evict(obj)            (or in future with JPA2: entityManager.detach(obj)  )


set read-only:

Code:
session.setReadOnly(obj, readOnly)


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