Skip to content

Update Testing chapter regarding avoiding false positives with JPA [SPR-9032] #13671

@spring-projects-issues

Description

@spring-projects-issues

Mattias Severson opened SPR-9032 and commented

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();
}

Affects: 3.1 GA

Issue Links:

Referenced from: commits 64c388d

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions