How do I properly annotate inheritance classes using ORMLite?

前端 未结 2 896
独厮守ぢ
独厮守ぢ 2021-01-05 13:25

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

2条回答
  •  花落未央
    2021-01-05 13:56

    The @DatabaseTable annotation is only necessary on the Student or Teacher tables and would not be used if it was on the Person base class.

    What you need to have is a @DatabaseField annotation on the id and name fields in Person. For example:

    public abstract class Person{
        @DatabaseField(generatedId = true)
        public int id;
        @DatabaseField
        public String name;
    }
    

    ORMLite should walk the class hierarchy and any fields from the base class should be included in the Student and Teacher tables. If you edit your question to show the @DatabaseField or other annotations, I can comment more.

提交回复
热议问题