ORMLite External Member Updates

I have a top-level element that I save in the database and it has several external elements, something like this:

@DatabaseTable public class Parent { @DatabaseField(id = true, index = true) public Integer id; @DatabaseField(foreign = true) public ChildA a; } @DatabaseTable public class ChildA { DatabaseField(generatedId = true, index = true) public Integer id; @DatabaseField public boolean something; } 

Suppose they are already created in a database. And now I want to update them. Will parentDao.update(parent) update both? Or do I also need to manually update it?

+4
source share
1 answer

Short answer:

no, it will not update both

Foreign objects are not proxy objects, so ORMLite cannot determine if a sub-object has been modified and needs to be updated. Therefore, if you change the Parent and ChildA , you will need to do something like:

  childADao.update(parent.a); parentDao.update(parent); 

Obviously, if you set the new ChildA child to the parent, it will update this new identifier in the parent table.

+7
source

All Articles