Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test context framework: @Transactional does not flush the Hibernate session before rollback [SPR-5315] #9988

spring-projects-issues opened this issue Nov 24, 2008 · 3 comments


Copy link

@spring-projects-issues spring-projects-issues commented Nov 24, 2008

Andy Kriger opened SPR-5315 and commented


  1. Create a unit test method like this...
    public void txTest()
    // do something to the db using Hibernate
    // do something else to the db using Hibernate that will trigger a Hibernate/db exception (ex: unique constraint violation)
    // sessionFactory.getCurrentSession().flush();

  2. Run the unit test method with and without the flush line

In both cases, an exception - the transaction should flush at the end of the method

Only when you flush manually do you get an exception.

Is the rollback=true skipping a session flush? Since rollback=true would only be used in a test (why would you do that in production code?), the transaction should always flush to ensure that the test activity occurs at the database level (even though you're going to rollback anyways). Otherwise, you get false positives which is dangerous in test code.

Affects: 2.5.4

Issue Links:

  • #10369 Test context framework: flush problems should lead to test exceptions instead of failures
  • #10613 Document potential false positives when testing ORM code

Referenced from: commits ee1938e

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Feb 17, 2009

Juergen Hoeller commented

As of Spring 3.0 M2, our TransactionalTestExecutionListener automatically flushes transactions before rolling back. It does so through the new "flush()" method on the TransactionStatus interface, which is also available to application code now.


Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 15, 2009

Sam Brannen commented

Reopened until the discussion in #10369 is concluded.

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 20, 2009

Sam Brannen commented

Reverted changes to TransactionalTestExecutionListener: transactions are no longer automatically flushed before rolling back.

For details explaining the reasoning, please see the discussion in #10369.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants