我有两个班级:
public class Questionnaire {
@DatabaseField(generatedId=true, useGetSet=true)
private Long id;
@DatabaseField
private int type;
@DatabaseField
private String title;
@DatabaseField
private String description;
@ForeignCollectionField(eager = true)
private Collection<Question> questions;
// Get and Set omitted
和
public class Question {
@DatabaseField(generatedId=true, useGetSet=true)
private Long id;
@DatabaseField
private int type;
@DatabaseField
private String description;
@DatabaseField(foreign = true, foreignAutoRefresh= true)
private Questionnaire questionario;
//get and set ommited
当我保存带有问题列表的问卷时。对象是持久的,但我失去了关系。
我这样保存:
ForeignCollection<Question> questions =
getDao(Questionnaire.class).getEmptyForeignCollection("questions");
for(Question question : DataUtil.getAllQuestions()) {
questions.add(question);
}
Questionnaire questionnarie = new Questionnaire();
questionnarie.setQuestions(questions);
questionnarie.setTitle("Normal");
questionnarie.setDescription("Questionário normal");
getDao(Questionnaire.class).createOrUpdate(questionarie);
当我从数据库中检索此寄存器时,Question
数据没有参考Questionnaire
,并且我Questionnaire
没有填写问题列表。
任何帮助将不胜感激。