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.
=====================================================================================
-
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