I\'m playing around a bit with JPA(Eclipselink to be specific). The below entity have a timestamp that\'s supposed to reflect whenever that entity was last updated.
Actually, surajz answer works. Consider a scenario where you are tracking 2 timestamps. You want to manually update them via the entity. You'd need to set one to updateble=false
(the one you do not want updated when the record is updated), and leave the other free for updates.
That's what worked for me.
if you are using mysql, I think you can do the following to disable the timestamps from being updated from entity
@Column(name = "lastUpdate", updatable= false, insertable=false)
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdate;
for oracle you time have to set the timestamps from the entity using @PreUpdate annotation as explained above.
Use @PrePersist and @PreUpdate annotations and write your own event listener.
Take a look at this answer for details. It's tagged as Hibernate but is applicable to any JPA provider.