java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethodTransactionalTestExecutionListener.java:175)

Spring JIRA | Alan Boshier | 2 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    This is similar but not identical to SPR-12245. Our base class tests are annotated as follows: {code:java} @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class }) @DbUnitConfiguration( databaseOperationLookup=ExtendedDatabaseOperationLookup.class, dataSetLoader=ColumnSensingDataSetLoader.class) public abstract class FooTestBase extends AbstractTransactionalJUnit4SpringContextTests implements FooTestInterface {code} ... with an annotated subclass: {code:java} @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(value = "/foo-context-test.xml") @TransactionConfiguration(defaultRollback = true) @Transactional public class FooTest extends FooTestBase { {code} In moving from Spring 4.0 to 4.1 we are seeing many of our tests fail with: {noformat} java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethodTransactionalTestExecutionListener.java:175) at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83) {noformat}

    Spring JIRA | 2 years ago | Alan Boshier
    java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethodTransactionalTestExecutionListener.java:175)
  2. 0

    This is similar but not identical to SPR-12245. Our base class tests are annotated as follows: {code:java} @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class, DbUnitTestExecutionListener.class }) @DbUnitConfiguration( databaseOperationLookup=ExtendedDatabaseOperationLookup.class, dataSetLoader=ColumnSensingDataSetLoader.class) public abstract class FooTestBase extends AbstractTransactionalJUnit4SpringContextTests implements FooTestInterface {code} ... with an annotated subclass: {code:java} @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(value = "/foo-context-test.xml") @TransactionConfiguration(defaultRollback = true) @Transactional public class FooTest extends FooTestBase { {code} In moving from Spring 4.0 to 4.1 we are seeing many of our tests fail with: {noformat} java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethodTransactionalTestExecutionListener.java:175) at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83) {noformat}

    Spring JIRA | 2 years ago | Alan Boshier
    java.lang.IllegalStateException: Cannot start a new transaction without ending the existing transaction. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethodTransactionalTestExecutionListener.java:175)

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Cannot start a new transaction without ending the existing transaction. at org.springframework.test.context.transaction.TransactionalTestExecutionListener.beforeTestMethodTransactionalTestExecutionListener.java:175)

      at org.springframework.test.context.TestContextManager.beforeTestMethod()
    2. Spring TestContext
      RunBeforeTestMethodCallbacks.evaluate
      1. org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249)
      2. org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72)
      2 frames
    3. JUnit
      RunAfters.evaluate
      1. org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      1 frame
    4. Spring TestContext
      SpringRepeat.evaluate
      1. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
      2. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
      2 frames
    5. JUnit
      ParentRunner.runLeaf
      1. org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      1 frame
    6. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)
      2. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
      2 frames