quarkus: Postgres timestamptz not working with Hibernate reactive?
Describe the bug I have a column in the Postgres with type of “timestamptz”. However, trying to use these fields in the Hibernate always result in:
io.vertx.core.impl.NoStackTraceThrowable: Parameter at position[0] with class = [java.time.LocalDateTime] and value = [2020-07-16T10:10:24.378] can not be coerced to the expected class = [java.time.OffsetDateTime] for encoding.
It does not seem to matter what how I set the type. I have tried the following types: Date, LocalDateTime, OffsetDateTime and Date with @Temporal(TemporalType.TIMESTAMP). I have also tried with @CreationTimestamp, @PrePersist and the same with update methods also.
Always the same error, so the transformation to types happens outside my code and my classes seem to have no effect at all.
The code that does the persist:
public Uni<Endpoint> createEndpoint(Endpoint endpoint) {
return mutinySession.onItem().produceUni(session -> session.persist(endpoint))
.onItem().produceUni(Mutiny.Session::flush)
.onItem().apply(ignored -> endpoint)
.onFailure().invoke(t -> {
System.out.printf("Failed to persist, %s\n", t.getMessage());
});
}
Expected behavior Timestamps should be persisted to Postgres.
Actual behavior Regardless of the type of property, the same error happens.
Environment (please complete the following information):
- Quarkus version or git rev: 1.6.0.Final
Additional context Dependencies related to db usage (if they matter):
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive-deployment</artifactId>
</dependency>
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 11
- Comments: 18 (13 by maintainers)
Commits related to this issue
- Correction problème mapping donnée timestampz postgres vers Instant Java https://github.com/quarkusio/quarkus/issues/10768 — committed to Mael-Brs/ecobenchmark-applicationweb-backend by Mael-Brs 2 years ago
- Add Benchmark Quarkus (#32) * Ajout gitignore * Ajout gitignore dockerignore * Mise à jour gitignore * Commit projet * Début implémentation panache * Implembtation des webservices *... — committed to Boavizta/ecobenchmark-applicationweb-backend by Mael-Brs a year ago
It’s been some time since I’ve looked at this issue but I don’t think we can solve it in Hibernate Reactive as discussed here.
The reason is that the type of the entity field is a
Dateand we expect to pass it to the vert.x client as aLocalDate. This would normally work because the column on the table would be a compatible type.In the case of the issue the column type of the table has been changed to something else and now the Vert.x client expect an
OffsetDateTime. The problem is that when the query get executed, Hibernate Reactive doesn’t know the table column type and so it still passes aLocalDateeven if now Vert.x expect anOffsetDateTime. I guess JDBC would do this kind of convertion automatically.I think this issue is more a responsibility of the Vert.x SQL client team. timestamp with timezone in PostgreSQL only stores the date as UTC, so I’m not sure why passing a
LocalDateis not allowed.Note that the reason we pass a
LocalDatein this case is that most databases don’t have a column type that keeps track of the timezones, so it wouldn’t be possible for Hibernate Reactive to read the correct timezone back.At the moment, I can only see two options:
UserType