gpt4 book ai didi

android - 房间 : Receiving error when using @Transaction

转载 作者:IT老高 更新时间:2023-10-28 13:32:06 26 4
gpt4 key购买 nike

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

A DAO method can be annotated with only one of the following:Insert,Delete,Query,Update

这是我的课:

@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 注释的方法时,它会正常编译。有没有办法解决这个问题?

最佳答案

根据transaction documentation

Marks a method in an abstract Dao class as a transaction method.

将您的类(class)更改为:

@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)
}

}

关于android - 房间 : Receiving error when using @Transaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46730172/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com