• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Are UserTransactions propogated into other methods?

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several methods in a class which contain codes that should be run in the context of a transaction. These methods are being called by other methods of the class which create and begin a UserTransaction before making the method calls.

For example:

methodA() contains code which should be run in a transaction, but nowhere in the method is a transaction created or started.

methodB() creates and starts a UserTransaction, then calls methodA(). If methodA() completes successfully then the transaction is committed, otherwise the transaction is rolled back.


My question is whether or not the code in methodA() is in fact running within the transaction which was started in methodB(), as I assume. My worry is that perhaps the transaction is somehow suspended when methodA() starts running, and then resumes once methodA() returns. Can someone please enlighten me as to how this actually works, or perhaps point me to a good reference?

Thanks in advance for any help.


--James
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW the methods I'm referring to in the original post are not part of an EJB. I know that I could control this behavior via the ejb-jar.xml if the methods in question were part of an EJB, but I'm wondering about how this works outside of an EJB.


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


methodA() contains code which should be run in a transaction, but nowhere in the method is a transaction created or started.

methodB() creates and starts a UserTransaction, then calls methodA(). If methodA() completes successfully then the transaction is committed, otherwise the transaction is rolled back.


It works as you expected: methodA executes within the transaction started by methodB. However if methodA would have started a new transaction, then because J2EE doesn�t support nested transactions, your first scenario will become valid: the transaction will get suspended and methodA will run within a new transaction. The initial transaction will resume after the second one will end.
Regards.
 
James Adams
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Valentin thanks for the confirmation -- now I can look elsewhere for my bug without worrying about a transaction related problem.


--James
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you're very welcome James
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic