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 ?