Based the documentation says:
We provide @CreatedBy
, @LastModifiedBy
to capture the user who created
or modified the entity as well as @CreatedDate
and @LastModifiedDate
to capture the point in time this happened.
I think the last one sentence means capture the point in time this happened by some user.
Since I had the same issue
a long time ago.
Then if you want to @CreatedDate
annotation works then you need to give a current auditor. Should create your custom Auditor Aware
by following way or simply the second one example.
First Example:
class SpringSecurityAuditorAware implements AuditorAware<User> {
public Optional<User> getCurrentAuditor() {
return Optional.ofNullable(SecurityContextHolder.getContext())
.map(SecurityContext::getAuthentication)
.filter(Authentication::isAuthenticated)
.map(Authentication::getPrincipal)
.map(User.class::cast);
}
}
Second Example:
class SpringSecurityAuditorAware implements AuditorAware<String> {
public Optional<String> getCurrentAuditor() {
return Optional.of("CurrentUser");
}
}
NOTE
I found an answer similar that you can check @CreatedDate does not work answer