Strange @PrePersist @PreUpdate behavior
I'm trying to add some auditing information to my records. My plan is as
follows:
@Temporal(TemporalType.TIMESTAMP)
@Column(updatable = false)
private Date created;
@Temporal(TemporalType.TIMESTAMP)
private Date updated;
@PrePersist
private void onCreate() {
created = new Date();
}
@PreUpdate
private void onUpdate() {
updated = new Date();
}
Using different versions of Hibernate, I'm observing the need to add the
following to the update:
@PreUpdate
private void onUpdate() {
if (created == null) {
created = new Date();
}
updated = new Date();
}
I.e. @PrePersist seems to not stick for my inserts. Is my attempt
conceptually wrong? If so, why? If not, what can we do to debug the
problem? The onCreate does get called, though, upon first insertion.
No comments:
Post a Comment