无法在集成测试中删除事务性为假的记录?

时间:2019-06-28 04:56:18

标签: grails grails-2.2

我有一个集成测试,其中我将transactional设置为false。在拆卸过程中,我此时遇到错误RaceGroup.list()。each {it.delete(flush:true)}。该错误表明只读模式下不允许写操作。所以我想知道这个只读模式在哪里。是否由于事务== false导致此错误出现。我感谢任何见解。谢谢!

class ProductControllerTests extends GroovyTestCase{

    static Log log = LogFactory.getLog(this)
    static transactional = false

    SpringSecurityService springSecurityService
    ProductController controller

    @Before
    void setUp(){
        super.setUp()
        springSecurityService.reauthenticate(User.first().email)
        assert springSecurityService.isLoggedIn()
        controller = new ProductController()
    }

    @After
    void tearDown(){            
        super.tearDown()
        OrderTemplateProduct.executeUpdate('delete OrderTemplateProduct')
        InventoryOrder.executeUpdate('delete InventoryOrder')
        RaceGroup.list().each{ it.delete(flush: true) }
        Director.executeUpdate('delete Director')
    }

引发的错误如下:

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 product.ProductControllerTests$_tearDown_closure1.doCall(ProductControllerTests.groovy:52)
    at product.ProductControllerTests.tearDown(ProductControllerTests.groovy:52)


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.
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 product.ProductControllerTests$_tearDown_closure1.doCall(ProductControllerTests.groovy:52)
    at product.ProductControllerTests.tearDown(ProductControllerTests.groovy:52)

0 个答案:

没有答案