-->
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.  [ 5 posts ] 
Author Message
 Post subject: Can't get rid of org.hibernate.StaleObjectStateException
PostPosted: Tue Mar 02, 2010 4:12 pm 
Newbie

Joined: Tue Mar 02, 2010 3:51 pm
Posts: 3
I'm playing around with versioning since a week. The row will be updated once and only once after that is start throwing StalObjectStateException. Please help !!!

Here's the code.

hibernate mapping
Code:
<hibernate-mapping>
   <class name="com.xxx.loan.CompositeLoan" table="LOAN"
       schema="ABC" lazy="false">
        <id name="LoanId" type="long">
            <column name="ID_LOAN" />
            <generator class="assigned" />
        </id>
        <version column="DT_LST_UPDT" name="dtLstUpdt" type="XXTimeStampType" generated="always"/>
...........


java code
Code:
public static Session session = HibernateUtil.getSessionFactory().openSession();
      public static void main(String[] args)   {
      Transaction tx = null;
      try {
         tx = session.beginTransaction();
         TestProgram test = new TestProgram();
         long loanID = 812814486;   
         
         try{
                                              CompositeLoan loan2 = test.updateCompositeLoan(loanID);// call the method (below)
                                               session.save(loan2);                                               
                                              session.getTransaction().commit();
....
                                              session.close();

//method to be called from above
public CompositeLoan updateCompositeLoan(long loanID)throws Exception
   {   
      CompositeLoan loan = null;
      try
      {
         loan = (CompositeLoan)session.load(CompositeLoan.class, loanID);
         loan.setxxx(Boolean.TRUE);      
         final Calendar ddlpiDate = Calendar.getInstance();
         ddlpiDate.add(Calendar.MONTH, -1);
         ddlpiDate.set(Calendar.DAY_OF_MONTH, 15);
         loan.setxxxxxDate(new XXTimeStampType(ddlpiDate.getTime()));
         loan.setDtLstUpdt(new XXTimeStampType(System.currentTimeMillis()));

..............





getting the following error



org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xxx.loan.CompositeLoan#812814486]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.xxx.yyy.TestProgram.main(TestProgram.java:98)


Last edited by garygary on Wed Mar 03, 2010 11:46 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Can't get rid of org.hibernate.StaleObjectStateException
PostPosted: Wed Mar 03, 2010 10:02 am 
Newbie

Joined: Tue Mar 02, 2010 3:51 pm
Posts: 3
anyone ?? please give your thoughts as I'm stuck here....


Top
 Profile  
 
 Post subject: Re: Can't get rid of org.hibernate.StaleObjectStateException
PostPosted: Wed Mar 03, 2010 11:06 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
It's horrible to read your code the way you posted it. Please use the Code-tag and do not cut your code right in the middle of the methods, so that's easy to see, where you transaction boundaries are and where you update your entity a second time.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Can't get rid of org.hibernate.StaleObjectStateException
PostPosted: Wed Mar 03, 2010 11:48 am 
Newbie

Joined: Tue Mar 02, 2010 3:51 pm
Posts: 3
Sorry for the code clutter. I've made it more readable. Also indicated the transaction boundries.


Top
 Profile  
 
 Post subject: Re: Can't get rid of org.hibernate.StaleObjectStateException
PostPosted: Wed Mar 03, 2010 11:58 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
You should not call save on an already persistent object. Use update instead. Maybe this helps already. btw, using a static member to store your session: why?

_________________
-----------------
Need advanced help? http://www.viada.eu


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