ORMLite与集合崩溃

时间:2014-10-11 21:29:24

标签: java android ormlite

我在android中使用ormlite来保存我的数据。 我有这个错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firext.android/com.firext.android.activities.reportList.ReportListActivity}: java.lang.RuntimeException: java.sql.SQLException: Foreign collection class com.firext.android.model.bbdd.DBQuestionsGroup for field 'questionsGroup' column-name does not contain a foreign field named 'questionsGroupsList' of class com.firext.android.model.bbdd.DBQuestions

我的课就是这个;

    @DatabaseTable
    public class DBQuestionsGroup {

        @DatabaseField(generatedId = true, columnName = "_id")
        private Long ID;
        @DatabaseField(columnName = "times")
        private int times;
        @DatabaseField(columnName = "idQuestionsGroup")
        private int idQuestionsGroup;
        @DatabaseField(columnName = "nameQuestionsGroup")
        private String nameQuestionsGroup;
        @ForeignCollectionField
        private Collection<DBQuestion> questionsGroupsList;

getters and setter


@DatabaseTable
public class DBQuestion {

    @DatabaseField(generatedId = true, columnName = "_id")
    private int ID;
    @DatabaseField(columnName = "question")
    private String question;
    @DatabaseField(columnName = "questionOrder")
    private int questionOrder;
    @DatabaseField(foreign = true,foreignAutoCreate = true)
    private DBReplieType replyType;
    @DatabaseField(columnName = "idQuestion")
    private int idQuestion;
    @DatabaseField(foreign = true, foreignAutoRefresh= true)
    private DBQuestionsGroup DBQuestion;

问题是什么?

1 个答案:

答案 0 :(得分:0)

也许您需要以这种方式在DBQuestionsGroup类中设置ForeingCollection:

@ForeignCollectionField
private ForeignCollection<DBQuestion> questionsGroupsList;

此示例可以帮助您:https://github.com/j256/ormlite-jdbc/tree/master/src/test/java/com/j256/ormlite/examples/foreignCollection