本文介绍了室:使用@Transaction时收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在DAO类中有一个以@Transaction注释的方法,这会导致以下错误:

I'm have a method annotated with @Transaction in my DAO class, which is causing the following error:

这是我的课程:

@Dao interface Dao {

    @Insert(onConflict = REPLACE) fun insertList(chacaras: List<String>)

    @Query("SELECT * FROM chacara WHERE cityId = :cityId")
    fun getListOfCity(cityId: String): LiveData<List<String>>

    @Delete fun deleteList(chacaraList: List<String>)

    @Transaction
    fun updateList(list: List<String>){
        deleteList(list)
        insertList(list)
    }

}

当我删除使用@Transaction注释的方法时,它将正常编译.反正有解决此问题的方法吗?

When I remove the method annotated with @Transaction it compiles normally.Is there anyway to fix this?

推荐答案

根据交易文档

将您的班级更改为:

@Dao abstract class Dao {

    @Insert(onConflict = REPLACE) abstract fun insertList(chacaras: List<String>)

    @Query("SELECT * FROM chacara WHERE cityId = :cityId")
    abstract fun getListOfCity(cityId: String): LiveData<List<String>>

    @Delete abstract fun deleteList(chacaraList: List<String>)

    @Transaction
    open fun updateList(list: List<String>){
        deleteList(list)
        insertList(list)
    }

}

这篇关于室:使用@Transaction时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 00:22