假设 JPA-Entity Foo
。通过添加注释,我可以处理更新createdDate
和modifiedDate
属性。更改name
和持久后Foo
,createdDate
正确更新。但这不适用于实体bars
列表Bar
@Entity
class Foo {
...
String name;
@OneToMany(cascade = CascadeType.PERSIST)
List<Bar> bars;
Date modifiedDate;
Date createdDate;
@PrePersist
public void updateCreatedDate() {
dateCreated = new Date();
}
@PreUpdate
public void updateModifiedDate() {
lastModified = new Date();
}
...
}
@Entity
class Bar {
...
}
Foo
如果一项bars
更改并保持不变,是否可以更新?