Persisting a Collection class with ORMLite in android

落爺英雄遲暮 提交于 2019-12-03 03:54:08

@Robert is correct. When hibernate persists a collection (or even an array), it does so with hidden extra tables with foreign ids -- in other words hidden foreign collections. ORMLite tries to adhere to the KISS principle and so has you define the foreign collections "by hand" instead.

I've added more details about storing collections.

http://ormlite.com/docs/foreign-collection


This means that you cannot persist an Integer type because there is no foreign-id. Also, your code can define a foreign collection Collection<Order> or ForeignCollection<Order>. Either one will be set with a ForeignCollection. ORMLite does not support lists or other collection types.

If you want to save a Collection (such as 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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!