1

我在连接工作时遇到问题,两个表定义如下:

public class Student { 
    @ForeignCollectionField(eager = true, columnName = STUDENT_INSTANCE_COLLECTION_NAME)
    private ForeignCollection<StudentInstance> studentInstances;

    ...
}

public class StudentInstance {
    public static final String STUDENT_ID_COLUMN = "student_id";
    public static final String REGISTER_ID_COLUMN = "register_id";

    @DatabaseField(generatedId = true)
    private int id;

    @DatabaseField(canBeNull = false, foreign = true)
    private Student student;

    @DatabaseField(canBeNull = false, foreign = true)
    private Register register;

   ...

}

活动代码:

public List<Student> getStudents( int registerId ) {
    QueryBuilder<StudentInstance, Integer> studentInstanceQb =  studentInstanceDao.getDAO().queryBuilder();
    studentInstanceQb.where().eq(StudentInstance.REGISTER_ID_COLUMN, registerId);
    QueryBuilder<Student, Integer> studentQb =  getDAO().queryBuilder();    
    studentQb.join(studentInstanceQb).query();
}

当我运行代码时,我得到了异常:

getStudents 上的错误:java.sql.SQLException:在 com.beardedhen.roster.db.entity.StudentInstance 类中找不到外部类 com.beardedhen.roster.db.entity.Student 字段,反之亦然

这可能是一个愚蠢的错误,但我已经用它击中了一堵完整的砖墙。

谢谢你的帮助,

安迪

4

1 回答 1

0

看看 QueryBuilder。matchJoinedFields(),异常来自哪里。您将看到当前 (4.42) 实现如何检查表并查找连接的列以进行连接。

于 2013-01-14T16:30:13.110 回答