This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes how to understand PROPAGATION_REQUIRED ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "how to understand PROPAGATION_REQUIRED ?" Watch "how to understand PROPAGATION_REQUIRED ?" New topic
Author

how to understand PROPAGATION_REQUIRED ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798

In documentation, it says: "PROPAGATION_REQUIRED: Support a current transaction, create a new one if none exists."; the problem that difination is trying to solve is like this :

Say, I define "update*", "insert*" as PROPAGATION_REQUIRED


So in line 2, it will NOT start a new transaction, it will use same transaction in line 1.

My understanding is correct ?

Thanks.
karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86
Hi Edward,

If the propagation is set to required then

1.If the calling method is already in a transaction it will use the same transaction
2.If the calling method is in a non-transaction scope it will create new transaction .


Correct me if I'm wrong .


Regards,
Karim.

karim
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

karimkhan pathan wrote:Hi Edward,

If the propagation is set to required then

1.If the calling method is already in a transaction it will use the same transaction
2.If the calling method is in a non-transaction scope it will create new transaction .


Correct me if I'm wrong .


Regards,
Karim.


You are absolutely correct.

For the original poster, setting a propogation is about what happens from the outside coming in. Meaning is the caller already in a Transaction or not. In your example line one is the definition of your method, not a line of code that runs. So you call that method and what is inside that method will always run in a Transaction, either by a transaction created by the calling code, or a new transaction created by calling the method if the calling code is not running in a Transaction already.

Example, two classes A and B. A is calling a method on B. B's method is marked at REQUIRED. If A has already started a Transaction, then B will just join that Transaction and run within it. So if A or B causes the transaction to rollback, everything will rollback. If A has not started a Transaction, then the call to B will create a new Transaction and all the code in B will be within the Transaction, but all the code in A is running outside of a transaction.

-------------------B's method is set to REQUIRED
A------------------B
TX----------------Joins A TX
NO TX -----------Starts New TX


Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to understand PROPAGATION_REQUIRED ?
 
Similar Threads
Spring Transaction using Spring AOP
Why it is making soo many tansactions?
Questions about tx in Spring
JDBCContext returning TransactionManager as null
HibernateDaoSupport and Transaction