java—为什么hibernatetransactionmanager创建新会话持有者

cdmah0mi  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(215)

调试时遇到如下情况:
在Spring5中,类hibernatetransactionmanager有以下代码:

// ...
if (!txObject.hasSessionHolder() || txObject.getSessionHolder().isSynchronizedWithTransaction()) {
    Interceptor entityInterceptor = getEntityInterceptor();
    Session newSession = (entityInterceptor != null ?
                        obtainSessionFactory().withOptions().interceptor(entityInterceptor).openSession() :
                        obtainSessionFactory().openSession());
    txObject.setSession(newSession);
}
// ...

如果现有会话的issynchronizedwithtransaction为true,为什么要创建新的会话持有者?结果,线程绑定的会话被替换为新会话。似乎同步的重点是在事务中使用同一个会话,还是我理解错了?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题