I have a Quarkus application where I persist data using Vert.x Reactive PostgreSQL Client.
Here ist the entity bean to be persisted:
public class SomeEntity {
public Long id;
public Integer f1;
public Boolean f2;
public SomeType f3;
public OffsetDateTime f4;
...
Problem is the f4
field with type OffsetDateTime
. Before persisting, It has the value of 2020-09-11T19:07:46.822828+02:00
with the offset +02:00
for Berlin GMT+2
When this record is persisted into PotgreSQL I see the value (in pgAdmin 4) being saved as 2020-09-11 17:07:46.822828+00
(in UTC without the offset). When I retrieve it back, the offset is gone.
I would like to retrieve this back with the timezone offset.
Here is the code snippet I use for persisting entities:
@QuarkusTest
public class SomeEntityRepositoryTest {
static final Duration TIMEOUT = Duration.ofSeconds(2);
@Inject
Pool client;
private Long idToGet;
@BeforeEach
public void initDatabase() {
idToGet = createOne(new SomeEntity(null, 17983,
false, SomeType.values()[0],
OffsetDateTime.now()));
}
protected SomeEntity from(Row row) {
return new SomeEntity(row.getLong("id"),
row.getInteger("f1"),
row.getBoolean("f2"),
SomeType.valueOf(row.getString("f3")),
row.getOffsetDateTime("f4"));
}
protected Long createOne(SomeEntity someEntity) {
return client.preparedQuery("INSERT INTO SOME_ENTITY (f1, f2, f3, f4) "
+ "VALUES ($1, $2, $3, $4) "
+ "RETURNING id, f1, f2, f3, f4")
.execute(Tuple.of(someEntity.f1,
someEntity.f2,
someEntity.f3.toString(),
someEntity.f4))
.map(RowSet::iterator)
.map(iterator -> iterator.hasNext() ? iterator.next() : null)
.map(this::from)
.map(inserted -> inserted.id)
.await()
.atMost(TIMEOUT);
}
Here is the DB Create script:
CREATE TABLE SOME_ENTITY (
id SERIAL PRIMARY KEY,
f1 integer,
f2 boolean,
f3 nvarchar,
f4 timestamptz
)
Those are the dependencies from my build.gradle
:
dependencies {
implementation enforcedPlatform("io.quarkus:quarkus-bom:1.7.3.Final")
implementation 'io.quarkus:quarkus-resteasy'
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
implementation "io.quarkus:quarkus-reactive-pg-client"
implementation "io.quarkus:quarkus-vertx"
implementation "io.quarkus:quarkus-resteasy"
implementation "io.quarkus:quarkus-resteasy-jackson"
implementation "io.quarkus:quarkus-resteasy-mutiny"
implementation "io.netty:netty-transport-native-epoll"
implementation "org.apache.commons:commons-lang3"
implementation "io.quarkus:quarkus-liquibase"
implementation "io.quarkus:quarkus-jdbc-postgresql"
}