【发布时间】:2017-09-26 09:29:56
【问题描述】:
我尝试将房间整合到我的项目中。我使用标准房autorGenerate = true 现场但它不起作用。我将新对象添加到 db,然后从 db 中获取。所有归档的 product_id 都以某种方式为空。我在产品创建中创建的所有其他文件都有值。在我看来
@PrimaryKey(autoGenerate = true)
public Integer object_id;
不生成任何东西。为什么这样?
@Entity
public class Prodcut {
@PrimaryKey(autoGenerate = true)
public Integer product_id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "is_cloud")
public Integer is_cloud;
@ColumnInfo(name = "user_id")
public Integer user_id;
}
【问题讨论】:
-
在大多数情况下,建议在 Integer 上使用 int 代替。你真的需要 Integer 类吗?
-
感谢它的帮助
-
我添加了答案以防止出现在未回答标签中。请接受。)
-
如果您使用的是 Integer 而不是 int,并且您不想更改它,您可以在插入之前将 product_id 设置为 null。
标签: android database android-room