我有这样的结构:
// all objects have valid mapping to database
public class Child {
private int id;
private String name;
}
public class Parent {
private int id;
private String name;
private List<Child> chidlren;
}
我必须更新父 A 中的特定子 B。
有两种方法:
更新集合内的子字段并更新整个对象:
Parent temp = dao.getParent(id);
temp.getChildren.get(0).setName('test');
dao.updateParent(temp);仅更新子对象:
Child temp = dao.getChild(id);
temp.setName('test');
dao.updateChild(temp);
如果我想获得更高的性能,哪个更好?
谢谢