Collections in ORMLite

痞子三分冷 提交于 2019-11-28 21:52:16

There are a number of resources and manuals that help with the usage of ORMLite under Android.

http://ormlite.com/docs/android
http://ormlite.com/docs/android-examples

To persist a collection, you must first get a Dao for the class and then create each of the objects using the Dao:

Dao<Person, Integer> personDao =
    DaoManager.createDao(androidConnectionSource, Person.class);
for (Person person : personCollection) {
    personDao.create(person);
}

Pretty much the same for your Phone class as well.


He was really asking about how to use the ForeignCollectionField feature of ORMLite. The documentation for this can be found here:

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

There is also an example project that uses it. In the above example, you are missing a Person field inside of Phone. If the person has a collection of phone objects then each phone object needs to have a corresponding person. This is called a "foreign object" in ORMLite.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!