How to store the arraylist in ormlite database

前端 未结 2 1513
天命终不由人
天命终不由人 2020-12-10 18:47

I am trying to save the arraylist of class objects into the ormlite database , but it is giving the error , java.lang.IllegalArgumentException: No fields have a DatabaseFiel

相关标签:
2条回答
  • 2020-12-10 19:13

    If you want to save an ArrayList of objects to ORMLite the easiest way is this:

    @DatabaseField(dataType = DataType.SERIALIZABLE)
    private SerializedList<MyObject> myObjects;
    

    and to get my list of objects:

    public List<MyObject> getMyObjects() {
      return myObjects;
    }
    

    and here is SerializedList:

    public class SerializedList<E> extends ArrayList<E> implements Serializable {
    }
    
    0 讨论(0)
  • 2020-12-10 19:23

    I think you need to use Foreign Collections. Take a look here:

    • Foreign Collections
    • Another similar question
    0 讨论(0)
提交回复
热议问题