-->
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: StaleObjectStateException after List reordering....
PostPosted: Sun Oct 10, 2004 3:17 pm 
Newbie

Joined: Fri Oct 03, 2003 6:47 am
Posts: 15
Hi,
I use Hibernate 2.1.6 and use versioning for concurrency and things work just fine. I have a problem with a side-effect after "reordering" a Collection List. Reordering means that two of the items switch place with each other.

I let the user move Items up and down in the GUI and behind the scene I use the .set method on my (Hibernate managed) List and it seems to work just fine but when I later want to update one of the moved child items i get a StaleObjectStateException. If I simply retry the same thing again the versioning seems to get back in sync and I can update the moved object.

Here is a snip (parts) from my mapping (XDoclet generated):

Code:
        <timestamp
            name="lastUpdatedDatetime"
            column="LAST_UPDATE"
        />

        <list
            name="appLayers"
            table="APP_LAYER"
            lazy="false"
            inverse="false"
            cascade="all"
        >

              <key
                  column="ID_APP"
              >
              </key>

              <index
                  column="LAYER_ORDER_NO"
              />

              <one-to-many
                  class="se.xxxxxxxx.AppLayer"
              />
        </list>


Here is my reordering code:

Code:
        Transaction tx = null;
        try
        {
          Session session = HibernateSession.getSession();
          tx = session.beginTransaction();
          Application app = (Application)session.load(Application.class,applicationid);
          AppLayer theLayer = app.getApplayerById(applayerid);
          List appLayers = app.getAppLayers();
          int currentPosition = appLayers.indexOf(theLayer);
          int newposition = currentPosition+positionAdjuster; // -1 or +1
         
          // Check newposition validity!
          if ((newposition > (appLayers.size()-1))||(newposition < 0))
          {
             c_Log.debug("Skipping layermove as new position is out of possible scope. newpos="+newposition+" layerList size="+appLayers.size());
             tx.commit();
             return;
          }
         
          AppLayer theSwapLayer = (AppLayer)appLayers.get(newposition);

          appLayers.set(newposition,theLayer);
          appLayers.set(currentPosition,theSwapLayer);

          // Trigger save of new collection ordering....
          session.update(app);
          session.flush();
          tx.commit();
        catch (HibernateException he)
        {
          try
          {
            if (tx != null) tx.rollback();
          }
          catch (HibernateException heRoll)
          {
            c_Log.fatal("Could not rollback!",heRoll);
          }
          c_Log.fatal("Could not move layer (id="+applayerid+") "+direction+"wards.",he);
          throw new ServiceException(he,ServiceException.SRV_EXC_NORMAL);
        }


Top
 Profile  
 
 Post subject: Evict of Second level cache needed after re-ordering
PostPosted: Tue Oct 12, 2004 2:23 am 
Newbie

Joined: Fri Oct 03, 2003 6:47 am
Posts: 15
I found a workaround regarding my problem. I use second level cache and I saw that when I reordered the list my versioning (lastUpdatedTimestamp) was updated (by Hibernate) in the database but when accessing the child object direct in the next request I got an old lastupdate timestamp. Maybe due to that Hibernate cache still got an old version. This is strange as the timestamp gets propagated to the database and not to the object in the cache.

Code:
appLayers.set(newposition,theLayer);
appLayers.set(currentPosition,theSwapLayer);

// New manual eviction...
session.getSessionFactory().evict(Applayer.class, theLayer.getId());
session.getSessionFactory().evict(Applayer.class, theSwapLayer.getId());
 


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.