Announcement Announcement Module
No announcement yet.
Calling one transactional method from another Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling one transactional method from another

    Hello All!

    I have a probably dumb question about transactions: If I have something like this in my app context:
    	<aop:advisor pointcut="execution(* *..FooBarFacade.*(..))" advice-ref="txAdvice"/>
    <tx:advice id="txAdvice" transaction-manager="txManager">
    		<tx:method name="insert*"/>
    		<tx:method name="*" read-only="true"/>
    Then define two methods in FooBarFacade: insertFoo and insertBar, and then invoke insertBar from insertFoo, what will be happenning then when calling insertFoo? Will it run in one transaction or in two? So if something fails in insertFoo after insertBar was called will the results of insertBar be committed?

    Thanks in advance

  • #2
    This has been discussed many times on this forum, it worth doing a search - I'm sure you'll find some threads about this issue.
    Anyway, check this chapter from reference documentation, to get a better understanding of how your code will work.

    In your case, second method call (insertBar) will not be in a proxied environment, so no transactional behavior will be added to it. There will be one transaction, started by first method (insertFoo), but insertBar will not participate in that transaction.


    • #3
      Thank you! I've read this and it's was very helpful.

      But I don't understand why won't insertBar participate in the transaction? If I call for instance barDao.insertBar(), then it will, right? But this.insertBar() won't. Why?


      • #4
        If you call insertFoo and this calls insertBar it will participate in the transaction. The point is that insertBar wouldn't start a new transaction even if the propagation was set to REQUIRES_NEW.
        Last edited by karldmoore; Aug 29th, 2007, 11:03 AM.