Results 1 to 2 of 2

Thread: @Transactional on subclass

  1. #1
    Join Date
    Mar 2007
    Posts
    561

    Default @Transactional on subclass

    Hi,

    I have a subclass of an abstract class which is called by a TaskExecutor. It seems that then something goes wrong with @Transactional.

    public interface IFoo
    public abstract class AbstractFoo implements IFoo
    public class Foo extends AbstractFoo

    I have to annotate the abstract class with @Transactional, not the concrete subclass, otherwise no tx is created.

    So this works:

    @Transactional
    public abstract class AbstractFoo implements IFoo


    But this not:

    @Transactional
    public class Foo implements IFoo

    I'm using:

    <aop:config proxy-target-class="true">
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

    What is wrong here?

    Thank you

  2. #2
    Join Date
    Nov 2010
    Posts
    15

    Default

    Although you are programming against interfaces you have chosen to configure:
    <aop:config proxy-target-class="true">

    Why?
    This causes spring to use CGLIB, in order to create the transactional proxies to your classes. This apporach could lead to problems, if the class is final or some methods are declared final.
    Why? Because with CGLIB subclasses of the classes to be proxied are generated, and as we know: it is impossible to override final methods or subclass final classes. (Also CGLIB proxied classes have to have a no-.arg constructor. And you should not access instance variables directly in this case)

    Try using dynamic proxies.
    The dynamic proxy just implements your bean interface and all should be working.
    You only need:
    <tx:annotation-driven />

    and you might need as well:

    <context:component-scan base-package="foo*" />
    <context:annotation-config />

Posting Permissions

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