1 package de.spring.example.persistence.domain.audit;
3 import javax.inject.Inject;
5 import org.hibernate.envers.RevisionListener;
7 import de.spring.example.context.UsernameThreadContext;
9 public class MyCustomRevisionListener implements RevisionListener {
11 private UsernameThreadContext userNameThreadContext;
14 protected MyCustomRevisionListener() {
19 public void newRevision(Object revisionEntity) {
20 MyCustomRevision myCustomRevision = (MyCustomRevision) revisionEntity;
22 final String username = getSafeUsername();
23 myCustomRevision.setUsername(username);
27 private String getSafeUsername() {
28 String userName = userNameThreadContext.getUsername();
30 if (userName == null) {