Keep track of datetime an entity was last modified with Ebean in Play

TIL that Ebean helps you to keep track of the datetime an entity was last modified.

Note that I use Ebean in combination with Play Framework.

I wanted to implement a column last_modified_at, when a colleague showed me this commit. You simply can add a timestamp property to a model with the annotation @WhenModified. Ebean will set the timestamp to the datetime when the entitiy was last modified. For example:

private LocalDateTime whenModified;

According to Ebean: @WhenModified is effectively an alias for @UpdatedTimestamp and added to hint towards a better naming convention (WhenCreated, WhenModified).

Ebean has more extensions to the standard JPA mapping, see them and their documentation here.