I have several threads, each open a session and gain access to the same data set. One thread t1 changes the data and commits the change. (the change has been persisted and visual from the DB) Another thread t2 loads the same data record the print it out. However, I find that the data retrieved contains "old" data. I suppose it is because the data is read from the cache as t2 load the data previously. So I tried to use the refresh method from the session, still the "old" data is read. I further use the LockMode.READ in the refresh as the following, but the result is the same.
Code:
ThreadSessionHolder.get().refresh(thedataobject, LockMode.READ);
From the API doc, refresh is supposed to re-read the data from the database, and LockMode.READ "were read from the database in the current transaction, rather than being pulled from a cache." (Or do i misunderstand?)
Anyway, I try to do the update directly on the DB by SQL, and the session still read old data even using "refresh". I have tried to glance through Hibernate documentation and FAQ, but cannot find similar problem. Could anyone provide some suggestions how to solve such problem?