Results 1 to 2 of 2

Thread: Spring AOP Transactions

  1. #1
    Join Date
    Oct 2007
    Posts
    26

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    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....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •