Announcement Announcement Module
Collapse
No announcement yet.
UnexpectedRollbackException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • UnexpectedRollbackException

    I'm getting an UnexpectedRollbackException in a unit test and I'm a little confused as to why. I'm using Spring 2.5.6 with iBATIS 2.3.4, Unitils 2.2 and JUnit 4 on PostgreSQL 8.3.5.

    The test attempts to create a record that already exists in the database and expects to that to fail with a DataIntegrityViolationException.

    Code:
    @Test(expected=org.springframework.dao.DataIntegrityViolationException.class)
    public void createExistingShouldFail()
    {
        phraseImportanceDao.create(1, 0, 0);
    }
    And here's the DAO implementation:

    Code:
    @Transactional
    public GlobalImportanceFeedback create(int domainId, double offset, double stddev)
    {
        Map<Object, Object> map = createMap(new Object[][] {{"domainId", domainId}, {"offset", offset}, {"stddev", stddev}});
    
        getSqlMapClientTemplate().insert("CipPhraseImportance.create", map);
            
        return getGlobalImportance(domainId);
    }
    The query is incredibly simple:

    Code:
    <insert id="create" parameterClass="map">
    INSERT INTO global_importance_feedback
    (
      domain_id,
      importance_offset,
      importance_deviation
    )
    VALUES
    (
      #domainId#,
      #offset#,
      #stddev#
    )
    </insert>
    And finally, here's the exception:

    Code:
    Testcase: createExistingShouldFail took 0.147 sec
            Caused an ERROR
    Transaction rolled back because it has been marked as rollback-only
    org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
            at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:695)
            at org.unitils.database.transaction.impl.DefaultUnitilsTransactionManager.commit(DefaultUnitilsTransactionManager.java:139)
            at org.unitils.database.DatabaseModule.commitTransaction(DatabaseModule.java:419)
            at org.unitils.database.DatabaseModule.endTransactionForTestMethod(DatabaseModule.java:394)
            at org.unitils.database.DatabaseModule$DatabaseTestListener.afterTestTearDown(DatabaseModule.java:538)
            at org.unitils.core.Unitils$UnitilsTestListener.afterTestTearDown(Unitils.java:323)
            at org.unitils.UnitilsJUnit4TestClassRunner$TestListenerInvokingMethodRoadie.runBeforesThenTestThenAfters(UnitilsJUnit4TestClassRunner.java:159)
            at org.unitils.UnitilsJUnit4TestClassRunner.invokeTestMethod(UnitilsJUnit4TestClassRunner.java:95)
            at org.unitils.UnitilsJUnit4TestClassRunner.access$000(UnitilsJUnit4TestClassRunner.java:44)
            at org.unitils.UnitilsJUnit4TestClassRunner$1.run(UnitilsJUnit4TestClassRunner.java:62)
            at org.unitils.UnitilsJUnit4TestClassRunner.run(UnitilsJUnit4TestClassRunner.java:68)
    I'm puzzled as to why I'm seeing the UnexpectedRollBackException. Since the record already exists, the INSERT should fail and the transaction should roll back. This isn't unexpected to me...

    Obviously there's something I don't understand, but I'm really not sure what I'm doing wrong.

    Any suggestions or advice would be greatly appreciated.

    -Sean
Working...
X