Spring Framework
  1. Spring Framework
  2. SPR-7649

JpaExceptionTranslatorAspect is applied by default (without requiring @Repository)

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as Designed
    • Affects Version/s: 3.0.2
    • Fix Version/s: None
    • Component/s: Core:AOP, Data
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Support for Spring exception translation was recently moved into Spring Aspects under https://jira.springframework.org/browse/SPR-6275

      However, the advice (on EntityManager, at least) is being applied automatically, which conflicts with the EntityManager contract and could potentially cause serious failures (since the translated exceptions aren't checked, and code which tries to catch the JPA standard exceptions won't see them). The Spring documentation indicates that this advice will only be applied when @Repository is applied to the class in question, but it's applied uniformly.

      Sample code (test class not annotated with @Repository):

      @PersistenceContext
      EntityManager em;

      @Test(expected=javax.persistence.PersistenceException.class)
      public void testPersistenceException() {
      em.persist(new ObjectWithNotNullFields()); // should throw PersistenceException; throws JpaSystemException instead
      }

        Activity

        Hide
        Oliver Gierke added a comment -

        I've been trapped by this one as well. Although the feature Ramnivas mentioned is available in AspectJ 1.6.9 IIRC, the AspectJ Maven plugin does not expose the option yet (http://jira.codehaus.org/browse/MASPECTJ-88). So you face the uncomfortable situation that you can either apply all aspects from the Spring Aspects library to a given class or none. So there's probably nothing wrong from the Spring side here I think but users probably get trapped by this until the Maven plugin gets fixed.

        Show
        Oliver Gierke added a comment - I've been trapped by this one as well. Although the feature Ramnivas mentioned is available in AspectJ 1.6.9 IIRC, the AspectJ Maven plugin does not expose the option yet ( http://jira.codehaus.org/browse/MASPECTJ-88 ). So you face the uncomfortable situation that you can either apply all aspects from the Spring Aspects library to a given class or none. So there's probably nothing wrong from the Spring side here I think but users probably get trapped by this until the Maven plugin gets fixed.
        Hide
        Christopher Smith added a comment -

        I still haven't been able to try the Ramnivas's workaround (our build guru's been on vacation and then sick). I am not really familiar with AspectJ; is there a predicate in the pointcut specification that allows for selecting certain annotations on the target?

        In this case, for example, a user might in fact want exception translation applied to the Spring-aware pieces of an application but not to the generic JPA piece. How could she apply the aspect to just some of the classes in an large program?

        Show
        Christopher Smith added a comment - I still haven't been able to try the Ramnivas's workaround (our build guru's been on vacation and then sick). I am not really familiar with AspectJ; is there a predicate in the pointcut specification that allows for selecting certain annotations on the target? In this case, for example, a user might in fact want exception translation applied to the Spring-aware pieces of an application but not to the generic JPA piece. How could she apply the aspect to just some of the classes in an large program?
        Hide
        Daniel Cheng added a comment -

        Two years passed and nothing have fix this.

        I think the easiest "fix" should be just putting the roo specific into another maven-artifact (e.g. spring-roo-aspect)

        Show
        Daniel Cheng added a comment - Two years passed and nothing have fix this. I think the easiest "fix" should be just putting the roo specific into another maven-artifact (e.g. spring-roo-aspect)
        Hide
        Minas Manthos added a comment -

        +1 for split roo specific aspects

        Show
        Minas Manthos added a comment - +1 for split roo specific aspects
        Hide
        Chris Beams added a comment -

        Appears the 'solution' is build-level, not Spring-level; resolving as such.

        Show
        Chris Beams added a comment - Appears the 'solution' is build-level, not Spring-level; resolving as such.

          People

          • Assignee:
            Chris Beams
            Reporter:
            Christopher Smith
            Last updater:
            Trevor Marshall
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Days since last comment:
              1 year, 49 weeks, 6 days ago