jeudi 2 avril 2015

ORMLite update is not updating child records

I have a parent object that has a child table. I am using ORMLite 4.48 in Android.


Parent object (key attributes):



@DatabaseTable
public class Parent

@DatabaseField(generatedId=true)
private int id;

@DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true, canBeNull = false, columnName = CHILD_COLUMN)
private Child child;


Child object (key attributes):



@DatabaseTable
public class Child

@DatabaseField(generatedId=true)
private int id;

@DatabaseField(foreign = true, foreignAutoRefresh = true, columnName = PARENT_COLUMN)
private Parent parent;


Note that the Child object is setup so that foreignAutoCreate and foreignAutoRefresh are set to TRUE.


When I create the Parent object in the database I use:



getHelper().getParentDao().create(parent);


This automatically creates the Child record in the database. So far, perfect. However the problems arise when I subsequently update() the Parent object. For this I am using:



getHelper().getParentDao().update(parent);


This does not seem to be updating the Child record in the way that the create() method does.


My questions are do the create() and update() methods behave differently, in the way I have described, by design? If so, what is the best way to ensure that the Child record is updated? I assume by calling getHelper().getChildDao().update(child) just after the Parent has been updated?


Aucun commentaire:

Enregistrer un commentaire