Skip to content

Instantly share code, notes, and snippets.

@dilnei
Last active March 8, 2016 18:16
Show Gist options
  • Save dilnei/a02a55eab71f01dbdfac to your computer and use it in GitHub Desktop.
Save dilnei/a02a55eab71f01dbdfac to your computer and use it in GitHub Desktop.
listeners do Hibernate
/**
* The datetime that this record is created.
*/
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
/**
* The datetime that this record is modified.
*/
@NotNull
@Temporal(TemporalType.TIMESTAMP)
private Date lastModificationDate;
@PrePersist
public void whenInsert() {
creationDate = new Date();
lastModificationDate = new Date();
}
@PreUpdate
public void whenUpdate() {
lastModificationDate = new Date();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment