One connection in a spring transaction?

I have a few questions related to spring connections and transactions.

  • Does spring use the same connection instance when multiple transactions that perform DML and DDL operations are executed in a transaction (propagation level REQUIRED)? I read that he supports the same connection, but does not know why and how he does it technically? Explaining how any hints will be provided in the spring source code would be helpful.

  • Using spring declarative transactions, if I use Serializable as the isolation level, spring will make sure that one connection is always used when performing database operations in this method or in any other method called from the original transactional method

Are there any points that I should consider when working with spring Transactions that deal with this issue?

Any thoughts / help on this topic would be appreciated. Thanks.

Update 1 . I'm sorry for the mistake. I wrote a serializable distribution level instead of isolation level. Fixed.

+7
source share
1 answer
  • Spring Transaction Management is simply a unified interface for various transactional resources, such as JDBC connections. Since for most transactional resources it makes no sense to have a transaction that spreads across multiple connections, all operations in Spring-managed transactions for these resources are performed in the same connection. Of course, if you use distributed transactions with the JtaTransactionManager , each transactional resource involved in the distributed transaction will have its own connection.

  • Transaction isolation levels have nothing to do with Spring transaction management. Their meaning is defined in database theory . In addition, they are not related to the spread of transactions.

Spring implements this behavior by building connections (such as JDBC Connection s) as part of the local-stream state using the TransactionSynchronizationManager . See, for example, DataSourceUtils .

+5
source

All Articles