I'm trying to use inheritance with ORMLite and I can't work out if it is supported or not from looking at the documentation and googling.
What I want to do is have
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
}
What I can't work out (assuming it's supported) is how to annotate the 3 classes for ORMLite.
Do I only need to annotate the concrete classes with @DatabaseTable(tableName = "Student")
or do I need the abstract class also?
I keep getting errors like:
04-24 10:18:30.857: E/AndroidRuntime(30495): Caused by: java.lang.RuntimeException: java.sql.SQLException: Unknown field 'name' from the Android sqlite cursor, not in:[year, school]
Ok for that but now, how to implements, in that example, a fourth class containing a
List<AbstractPerson>
?I precise my question :
because when ormlite will try to access peoples like :
It won't be able to get personDAO because it doesn't exist (abstract)... I get all my database functionnal with good Id's and relation, it's just a data access question ?
The
@DatabaseTable
annotation is only necessary on theStudent
orTeacher
tables and would not be used if it was on thePerson
base class.What you need to have is a
@DatabaseField
annotation on theid
andname
fields inPerson
. For example:ORMLite should walk the class hierarchy and any fields from the base class should be included in the
Student
andTeacher
tables. If you edit your question to show the@DatabaseField
or other annotations, I can comment more.