The INFO
level should give a hint that this is not an error message. Your test rolls back by default, regardless of the primary setting on the service-level method. To avoid rollback (if you really want to) you need an annotation on the test class itself, as documented in the Annotations section of the Testing chapter in Spring documentation. The annotation in question is @Rollback
.
Spring transactionManager is Rolling back, while testexception=[null]!
-
30-06-2022 - |
سؤال
Why is the transaction being rolled back while there is no Exception
? The object is not being saved.
I have defined the transaction parameters like:
@Transactional(value = "transactionManager", timeout = 30, rollbackFor =
java.lang.Exception.class)`.
This is what logs say about the transaction.
org.springframework.test.context.transaction.TransactionalTestExecutionListener
endTransaction
INFO: Rolled back transaction after test execution for test context [TestContext@51e2a069
testClass = DAOTest, testInstance = sample.library.dao.DAOTest@7591777e, testMethod =
testSaveDao@DAOTest, testException = [null], mergedContextConfiguration =
[MergedContextConfiguration@213c2d7f testClass = DAOTest, locations =
'{classpath:/applicationcontext.xml}', classes = '{}', contextInitializerClasses = '[]',
activeProfiles = '{}', contextLoader =
'org.springframework.test.context.support.DelegatingSmartContextLoader', parent =
[null]]]
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.634 sec
Here is the whole log of DAOTest
class:
-------------------------------------------------------------------------------
Test set: sample.library.dao.DAOTest
-------------------------------------------------------------------------------
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.634 sec
what's being done wrong? I can give more information if necessary.
المحلول
لا تنتمي إلى StackOverflow