Skip to content

AuditAware not converting to ZonedDateTime anymore [DATAJPA-1242] #1579

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

Closed
spring-projects-issues opened this issue Jan 5, 2018 · 7 comments
Assignees
Labels
in: core Issues in core support status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug

Comments

@spring-projects-issues
Copy link

Hetmoteus opened DATAJPA-1242 and commented

I am using spring-boot 1.5.x with @EnableJpaAuditing

My entity has the following attribute :
@CreatedDate
protected ZonedDateTime createdAt;

It was working fine in spring-data 1.12.6.RELEASE converting from Calendar to ZonedDateTime.

Then I tried to switch to spring-boot 2 M7 which is using spring-data 2.0.2 and now I got the following error :
java.lang.IllegalArgumentException: Invalid date type for member ...

Seems like there is no converter between LocalDateTime and ZonedDateTime available.

Found a similar issue on spring-boot github:
spring-projects/spring-boot#10743


Affects: 2.0.2 (Kay SR2)

Reference URL: spring-projects/spring-boot#10743

Issue Links:

  • DATACMNS-639 Jsr310 support should include TimeZoned types

  • DATACMNS-834 Jsr310Converters does not support ZonedDateTime

  • DATACMNS-698 Add converter for OffsetDateTime and OffsetTime to JSR310 Converters

  • DATAREST-1355 LastModified header calculation does not support ZonedDateTime properties

  • DATACMNS-1243 Add converters Instant <-> LocalDateTime

@spring-projects-issues
Copy link
Author

Jens Schauder commented

There is already a little collection of issues asking for such a conversion

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Types with Zone information are very problematic. Especially in the context of Auditing. What timezone should get used? The one of the server where Spring is actually running? Of the user client (which is completely unknown to Spring Data).

Auditing should just record a point in time, which does not include a time zone. So that it ever worked could be considered a bug.

@spring-projects-issues
Copy link
Author

Hetmoteus commented

What about LocalDateTime which is used as replacement for Gregorian Calendar in the new version ?

LocalDateTime is not an Instant and therefor we won't have UTC time in database am I right ?

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Yes, by default the AuditingHandler will use the timezone of the JVM.

But the AuditingHandler which basically does the time stamping uses a DateTimeProvider.
The default one uses the default time zone.
But you can easily implement your own one, register it with name "dateTimeProvider" and it should get picked up.

And that can provide LocalDateTime instances based on UTC

@spring-projects-issues
Copy link
Author

Hetmoteus commented

Ok, but the current implementation is not recording "a point in time" when it is using LocalDateTime.
Maybe I'm wrong, but for me a point in time should not be relative to a timezone and should be fixed.
Wouldn't it better to have Instant instead of LocalDateTime then ?

@spring-projects-issues
Copy link
Author

Jens Schauder commented

After spending some time with this I agree. Created DATACMNS-1243 to handle that

@spring-projects-issues
Copy link
Author

Jens Schauder commented

Batch closing resolved issue without a fix version and a resolution indicating that there is nothing to release (Won't fix, Invalid ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support status: declined A suggestion or change that we don't feel we should currently apply type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants