Wednesday 1 February 2012

JPA: How to persist the loading time of an entity

@Entity
public class GenericEntity implements Serializable {

// ...

@Column(name="LOAD_DATE")
@Temporal(TemporalType.TIMESTAMP)
public Date getLoadDate() { return loadDate; }
public void setLoadDate(Date loadDate) { this.loadDate = loadDate; }

@PostLoad
public void postLoad() throws Exception {
  loadDate = new Date();
}

// ...

}

No comments:

Post a Comment