Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2010 15:26
What would you like to do?
DB independent and automatic update of create and update date fields - JPA
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import play.db.jpa.Model;
public class TemporalModel extends Model {
@Column(name = "created", nullable = false)
private Date created;
@Column(name = "updated", nullable = false)
private Date updated;
protected void onCreate() {
updated = created = new Date();
protected void onUpdate() {
updated = new Date();
public Date getCreated() {
return created;
public Date getUpdated() {
return updated;
public class BuildRecord extends TemporalModel { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment