我正在使用GreenDao制作一个Android应用程序,我有这两个实体:
@Entity
public class Quiz {
@Id(autoincrement = true)
private Long id;
private Date date;
private String type;
@ToMany(referencedJoinProperty = "quizId")
private List<Answer> answers;
}
@Entity
public class Answer {
@Id(autoincrement = true)
private Long id;
private int answer;
private float value;
private int questionNumber;
private String type;
private Long quizId;
}
我正在尝试使用以下代码获取测验列表:
DaoSession daoSession = AndroidAdapter.getDaoSession();
QuizDao quizDao = daoSession.getQuizDao();
List<Quiz> quizs = quizDao.loadAll();
但答案清单总是空着,我做错了什么?
答案 0 :(得分:0)
我的AndroidAdapter类:
public class AndroidAdapter {
public static Context getContext() {
return AppApplication.getContext();
}
public static DaoSession getDaoSession() {
return AppApplication.getDaoSession();
}
}
和AppApplication类
@Override
public void onCreate() {
super.onCreate();
context = this;
DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this,ENCRYPTED ? "exam-db-encrypted" : "exam-db");
Database db = ENCRYPTED ? helper.getEncryptedWritableDb("exam-secret") : helper.getWritableDb();
daoSession = new DaoMaster(db).newSession();
this.addAllEvents();
}
public static DaoSession getDaoSession() {
return daoSession;
}