@CreatedBy and @LastModifiedDate are no longer working with ZonedDateTime?
I had the same problem and could solve it adding a dateTimeProviderRef
to @EnableJpaAuditing
.
Java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.auditing.DateTimeProvider;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import java.time.ZonedDateTime;
import java.util.Optional;
@Configuration
@EnableJpaAuditing(dateTimeProviderRef = "auditingDateTimeProvider")
public class PersistenceConfig {
@Bean // Makes ZonedDateTime compatible with auditing fields
public DateTimeProvider auditingDateTimeProvider() {
return () -> Optional.of(ZonedDateTime.now());
}
}
Kotlin
@Configuration
@EnableJpaAuditing(dateTimeProviderRef = "auditingDateTimeProvider")
class PersistenceConfig {
@Bean // Makes ZonedDateTime compatible with auditing fields
fun auditingDateTimeProvider()= DateTimeProvider { of(ZonedDateTime.now()) }
}