You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
If you want to return a connection to connection pool after invoking a query, you don't add the @Transactional on your service method. If you add the @Transactiona on you service method, a connection is reused on each queries.This behavior is same with the JdbcTemplate provided by Spring Framework.
Hence; I think it's working as designed.
@kazuki43zoo ,thanks for your attention, I know if I remove the @transactional,it can works perfect, but what they could do if someone else use the spring aop configured by xml?
But you are right, this behavior is the same with the JdbcTemplate. After read the JdbcTemplate and the DataSourceTransactionTemplate again, I think, both SqlSessonUtils and DataSourceUtils provided by Spring Framework should use both TransactionSynchronizationManager.isSynchronizationActive and TransactionSynchronizationManager.isActualTransactionActive because it will be false if no transaction needed, am I right?
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?
The text was updated successfully, but these errors were encountered: