While debugging, I encountered the following situation:
In Spring 5, class HibernateTransactionManager have code:
// ...
if (!txObject.hasSessionHolder() || txObject.getSessionHolder().isSynchronizedWithTransaction()) {
Interceptor entityInterceptor = getEntityInterceptor();
Session newSession = (entityInterceptor != null ?
obtainSessionFactory().withOptions().interceptor(entityInterceptor).openSession() :
obtainSessionFactory().openSession());
txObject.setSession(newSession);
}
// ...
Why creating new session holder, if existing has isSynchronizedWithTransaction is true? As result, thread-bound session replaced with new session. It seems that the point of synchronization is to use the same session in a transaction, or do I understand it wrong?