I have a REST service which I'm calling from my app, which pulls in a JSON object as a byte[] that is then turned into a nice nested collection of objects -- all of that bit works fine. What I then want to do is persist these objects to SQLite storage using OrmLite, and that's where things start to break down, because as I understand, OrmLite doesn't automatically persist nested objects.

For simplicity, let's strip out my actual functionality and let my objects be modelled simply as followed:

@DatabaseTable(tableName = "parents")
public class Parent {

    @DatabaseField(id=true)
    private String name;

    @ForeignCollectionField
    // have to use Collection here because needs to be compatible with Jackson
    private Collection<Child> children; 

    /* Getters and setters go here */
}

@DatabaseTable(tableName = "children")
public class Child {

    @DatabaseField(id=true)
    private String name;

    @DatabaseField(foreign=true)
    private Parent parent;

    /* Getters and setters go here */
}

What happens is that when adding creating a new Parent object in the database with my corresponding parentDao object, the children are not being persisted along with the parent.

This is a common question and has been raised before, there are definitely other questions on SO which are very similar to this one, most notably Saving nested foreign objects with ORMLite on Android in answer to which Gray suggests creating the child object before the parent which would work fine for creating my POJOs manually.

However, I've not yet seen an answer which factors in cases where the objects are being generated by another library (in this case Jackson). Without digging deeper into Jackson's deserialisation innards (which removes the whole benefit of its simplicity)

Edit
Report