0

I'm trying insert current_timestamp to a database column "CREATION_DATE" when user is doing a create and set the current_timestamp to a database column "MODIFY_DATE" when user is doing an edit, but i failed. Code:

@Column(name = "CREATEDATE", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON INSERT CURRENT_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;

@Column(name = "MODIFYDATE", columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
private Date modifyDate;
javierpaniza
  • 677
  • 4
  • 10

1 Answers1

0

Add two callback methods to your entity:

@PrePersist
private void setCreateDate() {
    createDate = new Date();
}

@PreUpdate
private void updateModifyDate() {
    modifyDate = new Date();
}
javierpaniza
  • 677
  • 4
  • 10