Best way to store several ArrayLists in ORMLite for ApplicationSettings

database, java, orm, ormlite

Solution

For the arrayList you can simply do the following :

public class YourClass{
    @GeneratedId
    private int id;

    @ForeignCollectionField
    private Collection<MyString> bunchOfStrings = new ArrayList<MyString>();
    ...
}

In the MyString class you have the following :

public class MyString{
    @DatabaseField(canBeNull = true, foreign = true)
    private YourClass yourClass;

     @DatabaseField
     private String text;
    ....
}

And that's all

Problem

Right now I am trying to persist the Settings of an Application to my `DB` with the help of `ORMLite`. Well my settings consist of different `String[]` or `ArrayList<String>` or maybe a `Map` actually just a bunch of `Strings`. So my question is, what datatype should I use for such a scenario and optional maybe you could also provide me a small `code example`. Right now I tried different things, but I never was happy with the solution. I tried stuff like: ``` private HashMap<String, ArrayList<String>> configurationMap; private String[] stringArr1; private String[] stringArr2; private ArrayList<String> arrList1; ``` But when it comes to setup the `DB Datatypes` I always think, "I don't want an extra table to store the data" or "having a map serialized to the DB sucks...". Maybe anybody has an idea how to solve this in a nice and convenient way?

Original source

Related problems