Single Sugar ORM模型class不会保存会员?
Single Sugar ORM model class won't save members?
我过去曾成功地将 Sugar ORM 用于各种项目,并且遇到了一个非常不寻常的问题。
保存 "BoostTest" 数组时,其中 none 持久保存到数据库中。这个可以看here.
我正在 运行 批量插入之前删除并重新创建数据库。它适用于同一项目中的 many other model classes。
BoostTest.java 文件的代码与其他模型相同,只是构造函数、getter 和 setter。
我试过重命名 class,增加 Sugar ORM DB 版本,但我完全没有想法。此外,通过 BoostTest.save(new BoostTest(1,1,1,1));
语法保存记录也不起作用。
BoostTest.java:
package uk.co.jakelee.cityflow.model;
import com.orm.SugarRecord;
public class BoostTest extends SugarRecord{
private int boostId;
private int level;
private int owned;
private int used;
public BoostTest(int boostId, int level, int owned, int used) {
this.boostId = boostId;
this.level = level;
this.owned = owned;
this.used = used;
}
public int getBoostId() {
return boostId;
}
public void setBoostId(int boostId) {
this.boostId = boostId;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getOwned() {
return owned;
}
public void setOwned(int owned) {
this.owned = owned;
}
public int getUsed() {
return used;
}
public void setUsed(int used) {
this.used = used;
}
}
事实证明构造函数是必需的,即使你自己不使用它也是如此。 Sugar ORM 将在内部使用它。
将以下内容添加到 BoostTest.java class 解决了问题:
public BoostTest() { }
我过去曾成功地将 Sugar ORM 用于各种项目,并且遇到了一个非常不寻常的问题。
保存 "BoostTest" 数组时,其中 none 持久保存到数据库中。这个可以看here.
我正在 运行 批量插入之前删除并重新创建数据库。它适用于同一项目中的 many other model classes。
BoostTest.java 文件的代码与其他模型相同,只是构造函数、getter 和 setter。
我试过重命名 class,增加 Sugar ORM DB 版本,但我完全没有想法。此外,通过 BoostTest.save(new BoostTest(1,1,1,1));
语法保存记录也不起作用。
BoostTest.java:
package uk.co.jakelee.cityflow.model;
import com.orm.SugarRecord;
public class BoostTest extends SugarRecord{
private int boostId;
private int level;
private int owned;
private int used;
public BoostTest(int boostId, int level, int owned, int used) {
this.boostId = boostId;
this.level = level;
this.owned = owned;
this.used = used;
}
public int getBoostId() {
return boostId;
}
public void setBoostId(int boostId) {
this.boostId = boostId;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getOwned() {
return owned;
}
public void setOwned(int owned) {
this.owned = owned;
}
public int getUsed() {
return used;
}
public void setUsed(int used) {
this.used = used;
}
}
事实证明构造函数是必需的,即使你自己不使用它也是如此。 Sugar ORM 将在内部使用它。
将以下内容添加到 BoostTest.java class 解决了问题:
public BoostTest() { }