PROPAGATION_NESTED vs PROPAGATION_Required in spring?

Actually looking for difference between PROPAGATION_NESTED( Execute within a nested transaction if a current transaction exists) and PROPAGATION_Required(Support a current transaction).

Below is simple usecase

say in main class we call method1 and create the customer using jdbc[Transaction1]. Not commited yet.now we call the method2 in main class and create the account for the just created customer[Transaction2]. now commit it. can we call transactions 2 as nested transaction.

As per my understanding now if we define the transaction definition as PROPAGATION_NESTED

transaction 2 will be treated as nested but if we define it as PROPAGATION_Required it will support the current transaction. so whats the differnce between nested and required?


===========================================================================================

1 Answer




PROPAGATION_NESTED can only be used with a DataSourceTransactionManager and a JDBC3 driver. It uses save points in order to be able to rollback some part of a transaction (i.e. what constitutes the nested transaction in Spring terms). See the javadoc of Connection to see how save points work.

REQUIRED is completely different. It just means: if there is a transaction already existing, do the work in this transaction; else, start a new transaction, do the work, and commit the transaction.

answered  Jul 13 '11 at 19:04
JB Nizet
498k 48 774 929


=====================================================================================

  • Take a case of this example say in main class we call method1 and create the customer using jdbc[Transaction1]. Not commited yet.now we call the method2 in main class and create the account for the just created customer[Transaction2]. now commit it. As per your explanation both these transaction will be treated as part of one transaction(as there can be max one transaction with a connection)but if we use savepoints to partially rollback or commit we call transactions 2 as nested transaction.Is this correct? –  M Sach  Jul 14 '11 at 11:11 
  • @Mohit Gupta: You cannot partially commit using savepoints. –  Olaf  Jul 14 '11 at 20:55

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值