我想有两个主键,一个应该是自动生成的,我尝试这样做:
@Entity(tableName = "object_to_group", primaryKeys = {"id" , "object_id"},)
public class ObjectsToGroup {
@ColumnInfo(name = "id",autoGenerate = true)
public long id;
但是编译器显示错误
当我这样做时:
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
public long id;
编译器显示错误,我该怎么办?
复合主键无法添加自动增量。或者,您可以使用唯一索引。例如
@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;
}