@ PreUpdate @ PrePersist private void changeAuditInformation ( Auditable auditableEntity ) { Timestamp lastUpdated = new Timestamp ( System . currentTimeMillis ( ) ) ; auditableEntity . setLastUpdated ( lastUpdated ) ; String lastUpdatedBy = ServiceContextStore . getCurrentUser ( ) ; auditableEntity . setLastUpdatedBy ( lastUpdatedBy ) ; if ( auditableEntity . getCreatedDate ( ) == null ) auditableEntity . setCreatedDate ( lastUpdated ) ; if ( auditableEntity . getCreatedBy ( ) == null ) auditableEntity . setCreatedBy ( lastUpdatedBy ) ; }
set audit informations doesn t modify createdDate and createdBy once set . Only works with DomainObjects that implement the Auditable interface . In other cases a IllegalArgumentException is thrown .