开发者

ORMLite foreign member updates

I have a Top level element that I'm saving to the database, and it has several foreign 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;
}

Assuming these have already been created in the database. And now I want to update them. Will calling parentDao.update(parent) update both? Or 开发者_如何学JAVAdo I need to manually update the child as well?


The short answer is:

no, it won't update both

Foreign objects are not proxy objects so there is no way for ORMLite to determine if the sub-object has been modified and needs to be updated. So if you change both the Parent and ChildA objects then you'd have to do something like:

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

Obviously, if you set a new ChildA on parent then it will update this new id in the parent table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜