Monday, 30 September 2013

Spring JPA Auditing empty createdBy

Spring JPA Auditing empty createdBy

I am using the auditing capabilities of Spring Data and have a class
similar to this:
@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@Table(name="Student")
public class Student {
@Id
@GeneratedValue (strategy = GenerationType.AUTO)
private Long id;
@CreatedBy
private String createdBy;
@CreatedDate
private Date createdDate;
@LastModifiedBy
private String lastModifiedBy;
@LastModifiedDate
private Date lastModifiedDate;
...
Now, I believe I have configured auditing fine because I can see that
createdBy, createdDate, lastModifiedBy and lastModifiedDate all are
getting the correct values when I update the domain objects.
However, my problem is that when I update an object I am losing the values
of created By and lastModifiedBy. So, when I first create the object I
have all four values, but when I update it createdBy and createdDate are
nullified ! I am also using the Hibernate envers to keep a history of the
domain objects.
Do you know why do I get this behavior ? Why do createdBy and createdDate
are empty when I update the domain object ?

No comments:

Post a Comment