-->
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: concurrent updates without StaleObjectStateException
PostPosted: Mon Mar 17, 2008 4:16 pm 
Newbie

Joined: Mon Mar 17, 2008 4:01 pm
Posts: 1
I've set up versioning for my test application (I can see version number being increased after each updates) and I'm executing the following method in two threads :


Code:
public void run() {
   logger.trace("Thread ID : " + Thread.currentThread().getId());
   
   Session session = hibertest.sessionFactory.openSession();
   Transaction transaction = session.beginTransaction();

        //load the first record
      Device devRef = (Device) session.load(Device.class, new Integer(1));

        //modify just one field
   devRef.setModel(model);
   try {
       Thread.sleep ( tSleep );
   } 
   catch ( InterruptedException e ) {
   }

   transaction.commit();
   session.close();

   logger.trace("Thread ID  out : " + Thread.currentThread().getId());
    }


The the second thread starts with a delay of 5s and each thread sleeps for 10s. My problem is that the second thread overwrites the modifications of the first thread and I don't get any exception (I was expecting StaleObjectStateException).
I'm using Hibernate3, the versioning is set to "version"

What am I doing wrong ?


Top
 Profile  
 
 Post subject: Re: concurrent updates without StaleObjectStateException
PostPosted: Wed Mar 19, 2008 11:34 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Hmm, what is the mapping for Device? and what is the hibernate configuration file? In addition it is a little risky to mute that exception on sleep. Print something there that you also know if the thread is really sleeping.


Farzad-


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.