1 package de.spring.example.persistence.domain.audit;
3 import org.hibernate.envers.RevisionListener;
5 import de.spring.example.context.UsernameThreadContext;
7 public class MyCustomRevisionListener implements RevisionListener {
8 private final UsernameThreadContext userNameThreadContext;
10 public MyCustomRevisionListener(UsernameThreadContext userNameThreadContext) {
11 this.userNameThreadContext = userNameThreadContext;
15 public void newRevision(Object revisionEntity) {
16 MyCustomRevision myCustomRevision = (MyCustomRevision) revisionEntity;
18 final String username = getSafeUsername();
19 myCustomRevision.setUsername(username);
23 private String getSafeUsername() {
24 String userName = userNameThreadContext.getUsername();
26 if (userName == null) {