我想有两个主键,其中一个应该是自动生成的,我试着这样做:
@Entity(tableName = "object_to_group",primaryKeys = {"id“,"object_id"},)公共类ObjectsToGroup {
@ColumnInfo(name = "id",autoGenerate = true)
public long id;但是编译器显示了错误
当我这样做的时候:
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
public long id;一个编译器告诉我错误,我应该怎么做?
发布于 2020-05-02 14:08:23
使用复合主键无法添加自动增量。作为另一种选择,您可以使用唯一索引。例如
@Entity(tableName = "object_to_group", indices = {@Index(value =
{"object_id"}, unique = true)})
public class ObjectsToGroup {
@PrimaryKey(autoGenerate = true)
private int id;
@ColumnInfo(name = "object_id")
private int object_id;
}https://stackoverflow.com/questions/60036437
复制相似问题