问题:
我有一个父类,其属性“lastUpdate”上带有@Version,用于并发检查。该父类具有 @OneToMany 关系,当我更新其子类时,我想自行更新字段“lastUpdate”,就像我更新其他字段时发生的情况一样。
在JPA中,有@OptmisticLocking(cascade = true)来执行此操作,但我找不到Ebean ORM的类似选项强>在Play2中。
重要:类之间没有 CascadeType。
代码:
@Entity
public class Child extends Model {
@ManyToOne()
@JoinColumn(name="parent_id")
public Parent parent;
}
@Entity
public class Parent extends Model {
@Version
public Date lastUpdate;
@OneToMany(mappedBy = "parent")
public List<Child> children = new ArrayList<Child>();
}
public class Application extends Controller {
public void updateChild(Parent p, Child c) {
...
c.save(); // or c.update()
p.children.set(c); // imagine a real code here updating, adding or removing a child.
p.update();
return;
}
}
您可以在这里找到类似的问题: Version of parent object is not incremented if one-to-many relationship of the parent object is modified
非常感谢... =)
最佳答案
登录为 https://github.com/ebean-orm/avaje-ebeanorm/issues/155
4.1.1 中将通过 markAsDirty() 方法支持。
p.markAsDirty();
p.update();
关于java - 当你更新它的子版本时,如何级联更新@Version?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24421129/