-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: testIssues in the test moduleIssues in the test moduletype: documentationA documentation taskA documentation task
Milestone
Description
Mattias Severson opened SPR-9032 and commented
Step by step:
- Go to http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#testcontext-tx
- Scroll down to "Avoid false positives when testing ORM code"
- 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:
- Doc: Flush in test with SessionFactory vs EntityManager [SPR-13723] #18296 Doc: Flush in test with SessionFactory vs EntityManager ("is duplicated by")
Referenced from: commits 64c388d
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test moduletype: documentationA documentation taskA documentation task