Announcement Announcement Module
Collapse
No announcement yet.
Spring AOP Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring AOP Transactions

    I am planning to use Spring AOP for Transaction, but because Spring AOP uses dynamic proxy, a self-call won't be "intercepted", but does it matter? Ie.

    @Transactional(rollbackFor = Exception.class)@T
    class MyService
    {
    void serviceA() throws Exception
    {
    serviceADao.doSomethingA();
    serviceB();
    }

    void serviceB() throws Exception
    {
    serviceBDao.doSomethingB();
    }
    }

    ServiceADao
    {
    public doSomethingA()
    throws Exception
    {
    Session hSession = getSession(); // Hibernate Session also DI.
    ...
    }
    }

    ServiceBDao
    {
    public doSomethingB()
    throws Exception
    {
    Session hSession = getSession(); // Hibernate Session also DI.
    ...
    }
    }

    A transaction T is created when serviceA() is invoked. What happens when serviceB() is invoked through serviceA()? Would serviceB() be enrolled in the same transaction? It's a self-call, but I figure, why would serviceB() not be in the same transaction?

    I need serviceB() to be enrolled in the same transaction as A. Do I need to use aspectJ ?

    Thanks...

  • #2
    All the calls will be in the SAME transaction, this is also explained in the reference guide (the part about proxying). So every method called from serviceA() will participate in the SAME transaction.

    Now if you would have a different transactional setting for serviceB(), for instance REQUIRES_NEW, then that would be ignored, due to the self invocation. If you would want that to happen, you would need AspectJ and loadtime weaving.

    Also please next time use [ code][/code ] tags when posting....

    Comment

    Working...
    X