-
-
Save stevetompson0/b915c39fa8b435a3f8b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import java.util.Date; | |
import javax.persistence.Column; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.Id; | |
import javax.persistence.MappedSuperclass; | |
import javax.persistence.PrePersist; | |
import javax.persistence.PreUpdate; | |
import javax.persistence.Version; | |
import play.db.ebean.Model; | |
@MappedSuperclass | |
public class Timestampable extends Model { | |
@Id | |
@GeneratedValue | |
public Long id; | |
@Column(name = "created_at") | |
public Date createdAt; | |
@Column(name = "updated_at") | |
public Date updatedAt; | |
@Version | |
public int version; | |
@Override | |
public void save() { | |
createdAt(); | |
super.save(); | |
} | |
@Override | |
public void update() { | |
updatedAt(); | |
super.update(); | |
} | |
@PrePersist | |
void createdAt() { | |
this.createdAt = this.updatedAt = new Date(); | |
} | |
@PreUpdate | |
void updatedAt() { | |
this.updatedAt = new Date(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment