-->
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.  [ 3 posts ] 
Author Message
 Post subject: StaleObjectStateException
PostPosted: Fri Jul 13, 2007 10:48 am 
Newbie

Joined: Mon Jul 24, 2006 10:01 am
Posts: 4
Greetings:

I was trying to SaveorUpdate a record in the database and I am getting the following StaleObjectStateException.

I am using Hibernate version 3.0.

The code between sessionFactory.openSession() and session.close():

Code:
try{
             session    = getHibernateSession();
              tx = session.beginTransaction();
              session.saveOrUpdate(registrationER);
              tx.commit();
           }catch(HibernateException he){
              log.error(he);
              try{
                 tx.rollback();
              }catch(HibernateException heh){
                 log.error(he);
              }                       
              if(he.getCause() != null){              
                 throw new DataAccessorException(he.getCause().getMessage());
              }else{
                 throw new DataAccessorException(he.getMessage());
              }
           }catch(Exception e){
              log.error(e);
              throw new DataAccessorException(e.getMessage());
           }finally{
              session.close();
           }       



Full stack trace of any exception that occurs:

Quote:
ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.vrs.selfserv.hibernate.dataobject.RegistrationEr#1534]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1699)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2342)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2242)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2542)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)




10:11:28,453 ERROR [RegistrationErDA] org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.vrs.selfserv.hibernate.dataobject.RegistrationEr#1534]
10:11:28,453 ERROR [LogInterceptor] EJBException in method: public abstract com.vrs.enterpriseintegrator.rims.dataobject.MemberData com.vrs.selfserv.session.interfaces.RegistrarErLocal.loginEmployer(com.vrs.selfserv.beans.LoginBean) throws javax.ejb.EJBException,com.vrs.selfserv.exceptions.LoginException, causedBy:
com.vrs.selfserv.exceptions.DataAccessorException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.vrs.selfserv.hibernate.dataobject.RegistrationEr#1534]
at com.vrs.selfserv.hibernate.dataaccess.RegistrationErDA.saveOrUpdate(RegistrationErDA.java:85)
at com.vrs.selfserv.session.ejb.RegistrarEr.loginEmployer(RegistrarEr.java:766)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)




The generated SQL (show_sql=true):

Code:
[STDOUT] Hibernate: update SelfService.dbo.RegistrationEr set LastChangeTs=?, ChallengeQuestionCode=?, VRSId=?, Password=?, PasswordChangeRequired=?, ChallengeAnswer=?, RecordLocked=?, SourceOfLock=?, LockTs=?, LastChangeUser=?, Username=?, RegistrationTs=?, AccessCode=?, RegistrationStep=?, LastPasswordChangeDate=? where RegistrationErIdent=? and LastChangeTs=?


The problem is my piece of code was working before for a long time..
I believe nothing changed at my end...

Any Ideas..?
I believe, there is no other transaction handling the same record.

Thanks in advance..

Regards,
Ganesh.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 12:06 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
Hi Ganesh

I imagine either your ID or Timestamp doesn't match whats currently in the database:
"where RegistrationErIdent=? and LastChangeTs=?"

Might be worth setting a breakpoint or doing some sysouts to verify this and see which field is at fault.

Mike


Top
 Profile  
 
 Post subject: StaleObjectStateException
PostPosted: Mon Jul 16, 2007 8:50 am 
Newbie

Joined: Mon Jul 24, 2006 10:01 am
Posts: 4
Hi Mike,

Thanks for your reply..
I have changed the LastChangeTs. Everytime, I change something in the record, I update LastChangeTs with the latest timestamp. This was the case so far and it worked fine..
I'm using the

Code:
session.saveOrUpdate(registrationER);


I don't understand, why its creating problems now, though it was like this for some time..and was working fine....


Quote:
2007-07-16 08:11:38,984 INFO [STDOUT] Hibernate: update SelfService.dbo.RegistrationEr set LastChangeTs=?, ChallengeQuestionCode=?, VRSId=?, Password=?, PasswordChangeRequired=?, ChallengeAnswer=?, RecordLocked=?, SourceOfLock=?, LockTs=?, LastChangeUser=?, Username=?, RegistrationTs=?, AccessCode=?, RegistrationStep=?, LastPasswordChangeDate=? where RegistrationErIdent=? and LastChangeTs=?



One more question, Is there a way to eliminate the LastChangeTs from the where clause..?? and make the generated sql as


Quote:
2007-07-16 08:11:38,984 INFO [STDOUT] Hibernate: update SelfService.dbo.RegistrationEr set LastChangeTs=?, ChallengeQuestionCode=?, VRSId=?, Password=?, PasswordChangeRequired=?, ChallengeAnswer=?, RecordLocked=?, SourceOfLock=?, LockTs=?, LastChangeUser=?, Username=?, RegistrationTs=?, AccessCode=?, RegistrationStep=?, LastPasswordChangeDate=? where RegistrationErIdent=?


Please notice, the LastChangeTs is not present in the where clause..How can I achieve this..??



Thanks,
Ganesh.


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