美文网首页
Google Room 坑点

Google Room 坑点

作者: 眺望天空 | 来源:发表于2019-08-05 00:48 被阅读0次
@Entity
data class User(
    @ColumnInfo(name = "category_id") var name: String
{
    @PrimaryKey(autoGenerate = true)
    var id: Long = 0
}

坑点:
1、如果字段类型为long或int(或其TypeConverter将其转换为long或int),则Insert方法在插入时将0视为未设置。

2、如果字段的类型是Integer或Long(Object)(或者其TypeConverter将其转换为Integer或Long),则Insert方法在插入时将null视为未设置。

未设置的情况下primaryKey才可以自增长,而不是在创建对象时传入。

相关文章

网友评论

      本文标题:Google Room 坑点

      本文链接:https://www.haomeiwen.com/subject/aogudctx.html