-->
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.  [ 1 post ] 
Author Message
 Post subject: Stale data associated with Tomcat threads - detached objects
PostPosted: Tue Mar 08, 2005 1:59 pm 
Newbie

Joined: Tue Mar 08, 2005 1:42 pm
Posts: 1
Hi,

Hibernate version: 3 RC1

We have a Struts appn that is using the session-per-request-detached object strategy running in Tomcat 4.1.31. The persistence layer is using the HibernateUtil in section 1.4 of the Hibernate docs.

The usecase we're working with goes like this :

(a) list of objects is fetched from datastore (Oracle 9i, using longs for versioning)
(b) a single object is fetched from that list by id and then edited
(c) object is persisted (ok)
(d) list of objects form (a) is retrieved again and displayed

The update in (c) is handled using this method :

Code:
   public Object mergeObject(Object obj) throws PersistenceException {
      Transaction tx=null;
      Object updatedObj=null;
      Session session = HibernateUtil.currentSession();
      try {
         tx = session.beginTransaction();
         updatedObj = session.merge(obj);      
         session.flush();
         tx.commit();
      } catch (HibernateException e) {
         e.printStackTrace(System.out);
         if (tx!=null) tx.rollback();
         String msg = "Exception MERGING object - rolling back";
         log.error(msg,e);
         throw new PersistenceException(msg, e);
      } finally {
         HibernateUtil.closeSession();
      }
      return updatedObj;
   }   


We're seeing some weird behaviour where dependent on the Tomcat thread retrieving the list of objects (a), we sometimes see stale data onscreen. This only happens with one out of 3 threads and appears intermittently but reproducibly.

ie after editing an object in the list, and repeatedly refreshing page (a) we get this...

Refresh page (a) - Thread-A : list of objects is up-to-date
Refresh page (a) - Thread-B : list of objects is up-to-date
Refresh page (a) - Thread-C : list of objects is STALE
Refresh page (a) - Thread-A : list of objects is up-to-date
etc

I'd understood that using a ThreadLocal, each thread would get it's own copy of the 1st layer cache. If so, how can we ensure that all replicas are consistent with current data such taht the page refresh returns the latest data on each refresh?

Many thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.