当我尝试在测试中删除域对象时,不允许在只读模式(FlushMode.MANUAL)中执行写操作

时间:2012-09-19 22:52:59

标签: grails integration-testing gorm

我有一个非常简单的域对象:

class CustomEventsTester {

    String value
}

和简单的测试方法

class GormEventsTest extends GroovyTestCase {
    static transactional = true

    void testDelete() {
        def tester = new CustomEventsTester()
        assert !tester.save(flush: true)
        tester.value = 'abc'
        assert tester.save(flush: true)
        tester.value = 'lets_change'
        assert tester.save(flush: true)
        tester.delete(flush: true)
    }
}

此测试在tester.delete行传递异常:  | org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition. at GormEventsTest.testDelete(GormEventsTest.groovy:13)

为什么?!

0 个答案:

没有答案