Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in mybatis with SqlSessionUtils#registerSessionHolder when using nested double datasource transaction? #291

Open
sheepguo opened this issue Mar 17, 2018 · 5 comments

Comments

@sheepguo
Copy link

Secne
DB action sequence and My problems

Detail

I think after step 2, the datasource 2 SqlSession should not be stored in the thread.

Code

SqlSessionUtils#registerSessionHolder

  private static void registerSessionHolder(SqlSessionFactory sessionFactory, ExecutorType executorType,
  PersistenceExceptionTranslator exceptionTranslator, SqlSession session) {
SqlSessionHolder holder;
if (TransactionSynchronizationManager.isSynchronizationActive()) {
  Environment environment = sessionFactory.getConfiguration().getEnvironment();

  if (environment.getTransactionFactory() instanceof SpringManagedTransactionFactory) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Registering transaction synchronization for SqlSession [" + session + "]");
    }

    holder = new SqlSessionHolder(session, executorType, exceptionTranslator);
    // Key Point: If transaction synchronization is active for the current thread, sqlsession is binded to the thread. I think this logic is wrong.
    TransactionSynchronizationManager.bindResource(sessionFactory, holder);
    TransactionSynchronizationManager.registerSynchronization(new SqlSessionSynchronization(holder, sessionFactory));
    holder.setSynchronizedWithTransaction(true);
    holder.requested();
  } else {

As I mentioned in the code, I think this logic is wrong. Binding sqlsession to the thread should have the condition as:

  • there is transaction that corresponds to the current sqlsession
    in this thread;

Version

Spring 4.3.5 & mybatis-spring 1.3.1


So I think this is a bug in mybatis-spring and I don't know how to fix it.

@kazuki43zoo
Copy link
Member

kazuki43zoo commented Mar 17, 2018

Could you provide a small reproduce project and test case class via GitHub repository?

@kazuki43zoo
Copy link
Member

@sheepguo
Sorry .. I don't understand yet what is problem. Could you provide a small reproduce project and test case class via GitHub?

@Mirror-007
Copy link

I can not understand this ,too.

@SZMOFEI
Copy link

SZMOFEI commented Mar 22, 2022

i find the same issue as follow , seem it can not close the sqlSession @69781f7d
事务问题

@kazuki43zoo
Copy link
Member

@SZMOFEI @sheepguo

Cloud you provide a small repro project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants