SugarORM 在创建对象时定义 ID
SugarORM define ID when object created
我有一个像这样的非常简单的对象:
public class Item extends SugarRecord {
Long id;
String uuid;
Integer minor;
Integer major;
public Item() { }
public Item(Long id, String uuid, Integer minor, Integer major) {
this.id = id;
this.uuid = uuid;
this.minor = minor;
this.major = major;
}
}
我希望给定的 ID 作为主键,我不希望新的 ID 由 sugarORM 自动生成。有可能做这样的事情吗? ...听起来很简单,但我想不通...
我想你可以使用@Unique注解。
可以使用@Unique 注释指定唯一约束。当前的默认行为是在发生冲突时替换。因此,如果违反唯一约束,它将替换现有行。
是的,这是可能的。语法正确。问题出在别处。更新模型后,数据库没有重新生成。
我有一个像这样的非常简单的对象:
public class Item extends SugarRecord {
Long id;
String uuid;
Integer minor;
Integer major;
public Item() { }
public Item(Long id, String uuid, Integer minor, Integer major) {
this.id = id;
this.uuid = uuid;
this.minor = minor;
this.major = major;
}
}
我希望给定的 ID 作为主键,我不希望新的 ID 由 sugarORM 自动生成。有可能做这样的事情吗? ...听起来很简单,但我想不通...
我想你可以使用@Unique注解。
可以使用@Unique 注释指定唯一约束。当前的默认行为是在发生冲突时替换。因此,如果违反唯一约束,它将替换现有行。
是的,这是可能的。语法正确。问题出在别处。更新模型后,数据库没有重新生成。