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

Update Testing chapter regarding avoiding false positives with JPA

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: 3.1 GA
    • Fix Version/s: 4.3 RC2
    • Component/s: [Documentation], Test
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      Step by step:

      1. Go to http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#testcontext-tx
      2. Scroll down to "Avoid false positives when testing ORM code"
      3. Find how to include SessionFactory and flush() is used to avoid false positives if you are using Hibernate.

      The information is good, but it is not applicable if you use JPA. To avoid false positives when using JPA (backed by Hibernate) I propose that you add a new snippet that the describes a different approach. Suggested implementation:

      @PersistenceContext
      EntityManager entityManager;
      
      @Test(expected = GenericJDBCException.class)
      public void updateWithSessionFlush() {
          updateJpaEntity();
          // Manual flush is required to avoid false positive in test
          entityManager.unwrap(Session.class).flush();
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sbrannen Sam Brannen
              Reporter:
              matsev Mattias Severson
              Last updater:
              Spring Issuemaster
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

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