Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7649

JpaExceptionTranslatorAspect is applied by default (without requiring @Repository)

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: 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:
      true

      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
      }

        Attachments

          Activity

            People

            • Assignee:
              cbeams Chris Beams
              Reporter:
              w_c_smith 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:
                6 years, 3 weeks, 3 days ago