dinsdag 16 februari 2010

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();

Geen opmerkingen:

Een reactie posten