Skip to content Skip to sidebar Skip to footer

Collections In Ormlite

Hello I want persist some collections data with ORMlite in my android app. For example : class Person { @DatabaseField(generatedId=true) private int id; @DatabaseField p

Solution 1:

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

http://ormlite.com/docs/androidhttp://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

Post a Comment for "Collections In Ormlite"