Announcement Announcement Module
Collapse
No announcement yet.
Calling one transactional method from another Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    Code:
    <aop:config>
    	<aop:advisor pointcut="execution(* *..FooBarFacade.*(..))" advice-ref="txAdvice"/>
    </aop:config>
    
    <tx:advice id="txAdvice" transaction-manager="txManager">
    	<tx:attributes>
    		<tx:method name="insert*"/>
    		<tx:method name="*" read-only="true"/>
    	</tx:attributes>
    </tx:advice>
    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
    Ilya

  • #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.

    Comment


    • #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?

      Comment


      • #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.

        Comment

        Working...
        X