Visibility of objects in different Hibernate sessions

牧云@^-^@ 提交于 2019-12-12 01:15:52

问题


FlushMode in both Sessions is set to AUTO.

Session A: Session begins

Session B: Session begins

Session A: Session creates new objects, Session#flush() is called, Session ends.

Session B: Session reads objects from database and Session#flush() is automatically performed before this operation. Will the newly created objects of Session A also be visible to Session B?


回答1:


It depends on your isolation level and the underlying database. Hibernate defaults the isolation level to the underlying database. MySQL's default is REPEATABLE_READ. This means that session B will see the update if A commits before B does its first read (regardless of whether this is a read of the updated entity in question, although I believe this is a MySQL specific behavior. Some databases may allow reads of unrelated entities).

If the isolation level is READ_COMITTED then session B will see the update from session A as long as session A commits before session B does the read you are interested in.

It's worth pointing out that flushes have absolutely no effect on this question unless you have absolutely no isolation. The only thing that matters is commits.



来源:https://stackoverflow.com/questions/13842357/visibility-of-objects-in-different-hibernate-sessions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!