How to Fix Meaningless 'system' Audit Trails in Spring Data JPA Services
Spring Data JPA's auditing feature can be set up in minutes using four annotations and @EnableJpaAuditing, but audit columns often default to 'system' in ways that make them unreliable. The problem arises because scheduled jobs, queue consumers acting on behalf of real users, and sessions not yet initialized all produce identical audit entries. A developer has documented a structured approach to resolving this by defining what AuditorAware.getCurrentAuditor() should return in each scenario outside an active HTTP request. The solution involves reading user identity from a session-scoped bean rather than relying solely on Spring Security's SecurityContextHolder. A companion demo repository with Spring Boot and H2 illustrates the two key situations with runnable tests.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in