-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Invalid date type exception when using JPA Auditor, SpringBoot 2.0.0.M5 #10743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This issue tracker is not the right place to report a Spring Data issue. Please use their tracker and rather than pasting code in a comment, share a sample that they can run. Thank you. |
@b1412 did you solve your problem? I have the same issue on Spring Boot 2.0.0.RELEASE |
Me too |
@nowakprojects in my case, the problem was in Spring Auditing. The module have their's own date time converter. You need to use |
Had the same issue, you have to use a custom
then declare it:
|
As of Spring Boot 2.0 the "java.time.ZonedDateTime" class is not supported for JPA auditing (AuditAware) out-of-the-box and required to register a DateTimeProvider bean. See reported issues DATAJPA-1242 (1) and GH-10743 (2). The usage of "ZonedDateTime" for auditing has been advised against because the time zone is really more of a presentation layer concern. The use of "LocalDateTime" is problematic as well. It does not represent a point of time but does so only together with a timezone. The current implementation of Spring "CurrentDateTimeProvider" uses the JVM default timezone. If an application runs in a cluster across time zones this results in values of "LocalDateTime" values that can't be compared anymore. The recommended class to use is "java.time.Instant" instead because there is no timezone involved, yet it specifies a point in time. For details see issue DATACMNS-1243 (3) which added converters for "Instant" <-> "LocalDateTime". References: (1) https://jira.spring.io/browse/DATAJPA-1242 (2) spring-projects/spring-boot#10743 (3) https://jira.spring.io/browse/DATACMNS-1243 GH-6
As of Spring Boot 2.0 the "java.time.ZonedDateTime" class is not supported for JPA auditing (AuditAware) out-of-the-box and required to register a DateTimeProvider bean. See reported issues DATAJPA-1242 (1) and GH-10743 (2). The usage of "ZonedDateTime" for auditing has been advised against because the time zone is really more of a presentation layer concern. The use of "LocalDateTime" is problematic as well. It does not represent a point of time but does so only together with a timezone. The current implementation of Spring "CurrentDateTimeProvider" uses the JVM default timezone. If an application runs in a cluster across time zones this results in values of "LocalDateTime" values that can't be compared anymore. The recommended class to use is "java.time.Instant" instead because there is no timezone involved, yet it specifies a point in time. For details see issue DATACMNS-1243 (3) which added converters for "Instant" <-> "LocalDateTime". References: (1) https://jira.spring.io/browse/DATAJPA-1242 (2) spring-projects/spring-boot#10743 (3) https://jira.spring.io/browse/DATACMNS-1243 GH-6
@Configuration
@EnableJpaAuditing(dateTimeProviderRef = "auditingDateTimeProvider")
public class PersistenceConfig {
@Bean(name = "auditingDateTimeProvider")
public DateTimeProvider dateTimeProvider() {
return () -> Optional.of(OffsetDateTime.now());
}
} |
I am using Spring Boot 2.5.5 with JDK 17 and was facing this issue. Your answer really helped me fix this error I was seeing. |
|
You sir saved my day. I have no idea why that works though and why the error message seems totatlly unrelated. |
JPA auditing is working perfectly with SpringBoot 1.5.8, but when I tried to upgrade springboot to 2.0.0.M5, I got the exception .
My base entity
All of my entities are extended from the base entity above for auditing.
The text was updated successfully, but these errors were encountered: