Spring Framework
  1. Spring Framework
  2. SPR-975

Transactional annotation on interface method doesn't work with cglib

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Won't Fix
    • Affects Version/s: 1.2 final
    • Fix Version/s: None
    • Component/s: Core:AOP
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      It appears that if you add an @Transaction annotation to the declaration of a method in an interface and use CGLIB proxies, then the transactional advice is not honoured. This works, however, if you use JDK proxies instead of CGLIB, or if you put the annotation on the actual implementation of the method.

      Also see http://forum.springframework.org/viewtopic.php?p=21043#21059

        Activity

        Hide
        Juergen Hoeller added a comment -

        This is actually caused by the way that JDK 1.5 annotations handle inheritance: Class-level annotations may be inherited from superclasses, but that's about it. No inheritance from implemented interfaces, and no inheritance at the method level.

        Have a look at JDK 1.5's Inherited meta-annotation, which defines that contract. Spring's Transactional annotation is marked as Inherited; there doesn't seem to me more we can do. The limitation is caused by JDK 1.5's general annotation model, not by Spring's use of it.

        The consequence is that annotations should always be present on the actually invoked method or class. In case of a JDK proxy, that would be the interface; in case of a CGLIB proxy, that would be the concrete target class.

        Juergen

        Show
        Juergen Hoeller added a comment - This is actually caused by the way that JDK 1.5 annotations handle inheritance: Class-level annotations may be inherited from superclasses, but that's about it. No inheritance from implemented interfaces, and no inheritance at the method level. Have a look at JDK 1.5's Inherited meta-annotation, which defines that contract. Spring's Transactional annotation is marked as Inherited; there doesn't seem to me more we can do. The limitation is caused by JDK 1.5's general annotation model, not by Spring's use of it. The consequence is that annotations should always be present on the actually invoked method or class. In case of a JDK proxy, that would be the interface; in case of a CGLIB proxy, that would be the concrete target class. Juergen

          People

          • Assignee:
            Juergen Hoeller
            Reporter:
            Charles Blaxland
            Last updater:
            Trevor Marshall
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              8 years, 46 weeks, 2 days ago