【发布时间】:2018-03-29 04:27:21
【问题描述】:
我正在使用 Room 持久库。我需要在一个表中添加两个主键,其中一个主键应该是自动递增的。我不知道实现这一点的确切语法。下面是我的模型类:
@Entity(tableName = "newsPapers", primaryKeys =
{"news_paper_id","news_paper_name"})
public class SelectNewsModel {
private int news_paper_id;
@ColumnInfo(name = "image_url")
private String imageUrl;
@ColumnInfo(name = "news_paper_name")
private String newsPaperName;
}
我想让“news_paper_id”自动递增。我该怎么做呢?
【问题讨论】:
-
为什么需要两个主键?如果两者相同?
-
@KuLdipPaTel 对不起,我不明白你的问题。我想要两个不一样的主键。一个是“news_paper_id”,另一个是“news_paper_name”。我希望“news_paper_id”自动递增!我希望这个解释能消除你的疑惑。
标签: android auto-increment composite-primary-key android-room