我是java编程的初学者。我尝试用spring数据编写简单的独立应用程序。对于我想要添加的基本示例http://spring.io/guides/gs/accessing-data-jpa/,审计机制将存储对象的先前值。我想在客户实体中,在@PreUpdate上存储另一个表中的旧值,但我不知道如何。
@Entity
@EntityListeners(AuditingEntityListener.class)
public class Customer implements Serializable {
...
@Transient
private transient Customer savedState;
@PreUpdate
public void onPreUpdate() {
if (!savedState.firstName.equals(this.firstName)) {
log.info(String.format("first name was modified, new value =%s, old value=%s",this.firstName, savedState.firstName ));
}
}
@PostLoad
private void saveState(){
this.savedState = (Customer) SerializationUtils.clone(this); // from apache commons-lang
}