Posts

Showing posts from January, 2017

Spring Data force version and lastmodified date to update on JPA Entity

Spring data has a feature that allows you to track automatically a certain amount of fields through annotations :@CreatedDate : The date on which the entity was created@CreatedBy : The user that created the entity@LastModifiedDate : The date the entity was last modified@LastModifiedBy : The user that modified last the entity@Version : the version of the entity (increased each time the entity is modified and savesd)Let's say for example we have this simple entity with the appropriate annotations : @Entity @EntityListeners(AuditingEntityListener.class) public class Contact implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Version() private Long version = 0L; @NotNull @CreatedDate private Date creationDate; @NotNull @Size(max = 50) @CreatedBy private String creationUserLogin; @NotNull @LastModifiedDate private Date m…