1

I have some unit tests that run fine under Java 11.x and a Docker container with PostgreSQL 12.x. I'm in the process of migrating the application into Java 17.x, and now there are several of these unit tests failing. As far as I can tell the issue is around the precision of LocalDateTime types.

[ERROR]   UnitTest.test1:334
expected: CustomType (3185, 1, Description, 2022-12-01T22:10:27.924910854, 2022-12-01T22:10:27.924951801, user, false)
 but was: CustomType (3185, 1, Description, 2022-12-01T22:10:27.924911, 2022-12-01T22:10:27.924952, user, false)
[ERROR]   UnitTest.test2:60
expected: CustomType2 (3182, Test, Hello, 2022-12-01T22:10:27.653447384, user, index, null, null, false, null)
 but was: CustomType2 (3182, Test, Hello, 2022-12-01T22:10:27.653447, user, index, null, null, false, null)
[ERROR]   UnitTest.test3:268
expected: CustomType (3184, 1, Description, 2022-12-01T22:10:27.863401246, 2022-12-01T22:10:27.863438735, user, false)
 but was: CustomType (3184, 1, Description, 2022-12-01T22:10:27.863401, 2022-12-01T22:10:27.863439, user, false)

The tests are simple: the auto-generated (jOOQ) objects are compared after being instantiated manually with some predefined data (the expected), and then saved/updated from the database (the actual). The types in the database are defined as timestamp and jOOQ generates a LocalDateTime (instead of an Instant I would say) for the same.

// Unit Test
CustomType instance = CustomType.builder()
    // ...rest of the fields ommited for brevity
    .lastUpdatedAt(LocalDateTime.now())
    .build();

CustomType result = repository.insert(instance);
instance.setId(result.getId());
Assertions.assertThat(result).isEqualTo(instance); // AssertJ
// Repository
public CustomType insert(CustomType data) {
  data.setId(null);
  CustomTypeRecord record = new CustomTypeRecord(); // ...nevermind using record here ;)
  record.from(data);
  data = mainDsl.insertInto(CUSTOM_TYPE)
      .set(record)
      .returning()
      .fetchOneInto(CustomType.class);
  return data;
}

I don't know where else to look for hint(s) of what's going on here. I'm certain there aren't any custom formatting done to the LocalDateTime types in the source code.


UPDATES

Dependencies after upgrading jOOQ to version 3.17.5:

$ ./mvnw dependency:list
...
[INFO] --- maven-dependency-plugin:3.3.0:list (default-cli) @ graphql-api ---
[INFO]
[INFO] The following files have been resolved:
[INFO]    org.springframework.boot:spring-boot-starter-jooq:jar:2.7.4:compile -- module spring.boot.starter.jooq [auto]
[INFO]    org.springframework.boot:spring-boot-starter-jdbc:jar:2.7.4:compile -- module spring.boot.starter.jdbc [auto]
[INFO]    com.zaxxer:HikariCP:jar:4.0.3:compile -- module com.zaxxer.hikari
[INFO]    org.springframework:spring-jdbc:jar:5.3.23:compile -- module spring.jdbc [auto]
[INFO]    jakarta.activation:jakarta.activation-api:jar:1.2.2:compile -- module jakarta.activation
[INFO]    jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile -- module java.xml.bind
[INFO]    org.springframework:spring-tx:jar:5.3.23:compile -- module spring.tx [auto]
[INFO]    org.springframework:spring-core:jar:5.3.23:compile -- module spring.core [auto]
[INFO]    org.springframework:spring-jcl:jar:5.3.23:compile -- module spring.jcl [auto]
[INFO]    org.jooq:jooq:jar:3.17.5:compile -- module org.jooq
[INFO]    io.r2dbc:r2dbc-spi:jar:0.9.1.RELEASE:compile -- module r2dbc.spi [auto]
[INFO]    org.reactivestreams:reactive-streams:jar:1.0.4:compile -- module org.reactivestreams [auto]
[INFO]    org.jooq:jooq-codegen:jar:3.17.5:compile -- module org.jooq.codegen
[INFO]    org.jooq:jooq-meta:jar:3.17.5:compile -- module org.jooq.meta
[INFO]    org.jooq:jooq-postgres-extensions:jar:3.17.5:compile -- module org.jooq.postgres.extensions
[INFO]    org.springframework.boot:spring-boot-starter-web:jar:2.7.4:compile -- module spring.boot.starter.web [auto]
...
x80486
  • 6,627
  • 5
  • 52
  • 111
  • What jOOQ version are you using? – Lukas Eder Dec 02 '22 at 13:05
  • I'm using version `3.16.6`. A peculiarity with this project is that the `jOOQ` tables and POJOs are manually auto-generated beforehand and stored in the repository, along with the source code. – x80486 Dec 02 '22 at 13:44
  • 1
    Can you try upgrading? This was fixed in 3.18.0, 3.17.4, 3.16.10: https://github.com/jOOQ/jOOQ/issues/13919. Many other issues have been fixed as well since 3.16.6... – Lukas Eder Dec 02 '22 at 14:01
  • Sure, I can definitely try that! Let me do the upgrade, regenerate everything, and will post the outcome here. Thanks for the tip, Lukas. – x80486 Dec 02 '22 at 14:10
  • I did upgrade `jOOQ` to version `3.17.5` and regenerated everything. I can see now that `DefaultCatalog` has `REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_17` and some minor enhancements in the files. Still, I'm getting the same errors with the precision in the timestamps. I've also checked (just in case) the effective `POM` with `./mvnw help:effective-pom` and the versions are correct. I'm excluding `org.jooq:jooq` from `org.springframework.boot:spring-boot-starter-jooq`, but as far as I can tell, redefining it should do the same — which I'm doing as well. – x80486 Dec 02 '22 at 16:57
  • @LukasEder FYI ... The OP missed tagging you. – Arvind Kumar Avinash Dec 02 '22 at 18:07

0 Answers0