Timestamps with hibernate annotations

When you want timestamps on objects persisted with hibernate you can add callback methods that initialize these Date properties properly.

@Table(name = "entities")
public class Entity {

private Date created;
private Date updated;

protected void onCreate() {
created = new Date();

protected void onUpdate() {
updated = new Date();

Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait