Problems saving Collection using ORMLite on Android

老子叫甜甜 提交于 2019-12-04 11:10:09

The problem is that you are not setting the questionario field on your Question objects. The relationship is from the Question to the associated Questionnaire. There is nothing in the Questionnaire table that points the other way. See the documentation on foreign objects.

I would recommend doing something like the following:

Dao<Questionnaire, Long> dao = getDao(Questionnaire.class);
ForeignCollection<Question> questions =
    dao.getEmptyForeignCollection("questions");

Questionnaire questionnarie = new Questionnaire();
questionnarie.setQuestions(questions);
questionnarie.setTitle("Normal");
questionnarie.setDescription("Questionário normal");
dao.createOrUpdate(questionarie);

for(Question question : DataUtil.getAllQuestions()) {
    // you must set the questionnarie field on the Question
    // if it is a generated-id, it must be set _after_ it has been created
    question.setQuestionnaire(questionnarie);
    questions.add(question);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!