JUnit tests always rollback the transactions

后端 未结 7 1284
死守一世寂寞
死守一世寂寞 2020-12-05 02:54

I\'m running a simple JUnit test agains an application DAO. The problem is that I always get:

javax.persistence.RollbackException: Transaction marked as roll         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 03:19

    From official Documentation:

    By default, test transactions will be automatically rolled back after completion of the test; however, transactional commit and rollback behavior can be configured declaratively via the @Commit and @Rollback annotations

    https://docs.spring.io/spring/docs/current/spring-framework-reference/html/integration-testing.html#integration-testing-annotations

    @Commit indicates that the transaction for a transactional test method should be committed after the test method has completed. @Commit can be used as a direct replacement for @Rollback(false) in order to more explicitly convey the intent of the code.

提交回复
热议问题