This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to understand PROPAGATION_REQUIRED ?

 
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
You can't have everything. Where would you put it?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic