I have a best practices question with regards to mapping Instant
to PostgreSQL TIMESTAMP
.
We've updated our app to Java 15 and the new enhancement of the system clock to nanosecond precision ( https://bugs.openjdk.java.net/browse/JDK-8242504 ) is incompatible with the TIMESTAMP limitations in Postgres. Time is different depending on the underlying OS, and Instant in Mac (Big Sur) does not give time in nanoseconds but in Linux does.
We use Instant types across our codebase. Our tests are comparing objects of type Instant in memory vs fetched so they fail depending on the OS they're running in.
In Linux, the Instant object in memory has a precision of nanoseconds, whilst the Postgres stored Instant (TIMESTAMP) has a precision of microseconds. The assertions fail:
java.lang.AssertionError: expected [2021-01-04T19:32:23.726475249Z] but found [2021-01-04T19:32:23.726475Z]
In Mac, the Instant object has a precision of microseconds which aligns adequately with the Timestamp precision of Postgres, so the tests pass as they've always done so far.
We would like to avoid truncating Instant or adding plugins to PG to support nanoseconds.
How do others deal with this issue in a robust comprehensive manner?