我正在尝试将继承与 ORMLite 一起使用,但通过查看文档和谷歌搜索,我无法确定它是否受支持。
我想做的是拥有
public abstract class Person{
public int id;
public String name;
}
public class Student extends Person{
public String school;
public String year;
// other student stuff
}
public class Teacher extends Person{
public String title;
// other teacher stuff
}
我无法解决(假设它受支持)的是如何为 ORMLite 注释 3 个类。
我是否只需要注释具体的类@DatabaseTable(tableName = "Student")
或者我还需要抽象类吗?
我不断收到如下错误:
04-24 10:18:30.857:E / AndroidRuntime(30495):引起:java.lang.RuntimeException:java.sql.SQLException:来自Android sqlite游标的未知字段“名称”,不在:[年份,学校]
The @DatabaseTable
仅需要在Student
or Teacher
表,如果它在Person
基类。
你需要拥有的是@DatabaseField
上的注释id
and name
领域在Person
。例如:
public abstract class Person{
@DatabaseField(generatedId = true)
public int id;
@DatabaseField
public String name;
}
ORMLite应遍历类层次结构,并且基类中的任何字段都应包含在Student
and Teacher
表。如果您编辑问题以显示@DatabaseField
或者其他注释,我可以评论更多。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)