当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Old data in result from new hibernate session

问题描述:

I faced an issue that a process receives old data from newly-opened hibernate session whereas that data is updated by another process through committed transaction and closing session after that. If I connect to database directly I can see the updated data. The Hibernate version is 4.1.9 and database is MySQL 5.6.

After reading a lot of similar problems I made sure that it's not caused neither by first level cache - new session is opened each time, nor by second level cache - it's not enabled. I also tried different options like flushing session after transaction and etc. but the hibernate was still returning old data instead of updated. Then I found quite old post on hibernate forum describing the same problem which was fixed by setting hibernate.connection.isolation to 2 (TRANSACTION_READ_COMMITTED). I gave a try to such approach and it works for me as well.

So actually the question why such change could be required for Hibernate and MySQL having default configuration, could someone please explain ?

p.s. I spent hours for solving this problem, but didn't find such solution on so. so may be it will save time for other people in the same situation.

p.p.s While posting this question I finally found another. So posted with the same problem and solution. but at the same time there are also many other similar questions without replies. May be one more post will give more chance to find the solution.

Link to the post at hibernate forum

Link to to the similar post at SO

分享给朋友:
您可能感兴趣的文章:
随机阅读: