question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Auditing should support Java 8 Date & Time types [DATACMNS-411]

See original GitHub issue

Nick Williams opened DATACMNS-411 and commented

This may or may not be in the right project. I think it is, but it may need to be moved to Spring Data Commons.

Currently, fields annotated @CreatedDate and @LastModifiedDate can be Joda Time’s DateTime or (I think) java.util.Date, java.util.Calendar, or java.sql.Timestamp. If it doesn’t support these last three types, it should.

Auditing should also support the Java 8 Date & Time API. Fields modified with one of these two annotations should be able to be java.time.Instant, java.time.LocalDateTime, java.time.OffsetDateTime, and java.time.ZonedDateTime


Affects: 1.7 M1 (Codd), 1.6.3 (Babbage SR2)

Issue Links:

  • SPR-11259 Add Converter implementations that convert legacy Date instances into JDK 8 date/time types (“depends on”)

  • DATAJPA-592 Auditing annotations not working when applied to methods

  • DATACMNS-307 Remove JodaTime dependency

Referenced from: commits https://github.com/spring-projects/spring-data-commons/commit/51b128fac1c17c8327d6fdd8c7ef87b039ac6c60

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:30 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
spyro2000commented, May 27, 2021

I can’t believe that this is still not working in 2021… For everyone tired of all this, just create this configuration class:

(Kotlin)

@Configuration
@EnableJpaAuditing(dateTimeProviderRef = "dateTimeProvider")
class PersistenceConfig {
    @Bean 
    fun dateTimeProvider() = DateTimeProvider { Optional.of(OffsetDateTime.now()) }
}
1reaction
schaudercommented, Mar 18, 2022

Using LocalDateTime as the basis certainly was a mistake an we should probable fix that.

That said, discussing this on an issue that was closed 8 years ago isn’t helpful either.

For the record: The issue was closed because we do support Java 8 java.time classes to the extend that we actually want to: Anything with time zone is really out of place in my and not only in my opinion, especially since support for those in JPA and JDBC is … sketchy.

In order to get this ticket here it’s well earned rest:

  • If you want us to change the implementation basis for Auditing time stamps from LocalDate to Instant please create a ticket for it. For that one a PR even without a ticket has also a good chance of acceptance.
  • If you think you really need support for OffsetDateTime you are free to create a fresh ticket as well. Just be aware that you’ll probably have to do some convincing.
Read more comments on GitHub >

github_iconTop Results From Across the Web

JPA 2.2 Support for Java 8 Date/Time Types - Baeldung
In this tutorial, we'll show how to map the various Java 8 Date and Time types. We'll especially focus on the ones that...
Read more >
Which java.time type best fits for auditing information?
I would go for Instant. The new java.time api is just better to use, if you do any further processing of your timestamp...
Read more >
Java SE 8 Date and Time - Oracle
The first classes you will probably encounter when using the new API are LocalDate and LocalTime . They are local in the sense...
Read more >
The Concept of Date and Time in Java-8 - Knoldus Blogs
We can have handle Date and Time in 3 ways: – LocalDate: LocalDate represents a date in ISO format (yyyy-mm-dd) without time. –...
Read more >
Java time migration guide | Elasticsearch Guide [8.5] | Elastic
Convert date formatsedit. To upgrade to Elasticsearch 8, you'll need to convert any joda-time date formats to their java-time equivalents.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found