Skip to content

mybatis-spring dose not obey the spring transaction propagation behavior #183

@gaohanghbut

Description

@gaohanghbut

I've met a problem when I hope my service method shouldn't be wrapped by a transaction.Because there's several http requests and the method took a long time to finish itself and then, many threads hold the jdbc connections too long that my connection pool is empty and many CannotGetJdbcConnectionException were be thrown. So I marked the method with @transactional(propagation = Propagation.NOT_SUPPORTED), but it dosn't work.

I checked the SqlSessionTemplate and found that it'll invoke SqlSessionUtils.registerSessionHolder method to bind the SqlSession to TransactionSynchronizationManager if the TransactionFactory is implemented by SpringManagedTransactionFactory. It only works well then my transaction propagation behavior is Propagation.REQUIRED I bet.

So I think we should reimplement the SqlSessionTemplate and writer a MybatisTransactionManager to take the place of SqlSessionSynchronization.

Or if there's a better choice for me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions