具有OffsetDateTime且没有偏移/时区的Quarkus保存实体

问题描述

我有一个 Quarkus 应用程序,使用 Vert.x Reactive Postgresql Client 持久存储数据。

在此处保留实体bean:

public class SomeEntity {
  public Long id;
  public Integer f1;
  public Boolean f2;
  public SomeType f3;
  public OffsetDateTime f4;
  ...

问题是类型为f4的{​​{1}}字段。在持久之前,它的值为OffsetDateTime,其偏移量2020-09-11T19:07:46.822828+02:00+02:00

当该记录保存到Potgresql中时,我看到值(在pgAdmin 4中)被保存为Berlin GMT+2(在UTC中没有偏移量)。当我取回它时,偏移量消失了。

我想用时区偏移量找回它。

这是我用于保留实体的代码段:

2020-09-11 17:07:46.822828+00

这是数据库创建脚本:

@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,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);
  }

这些是我的CREATE TABLE SOME_ENTITY ( id SERIAL PRIMARY KEY,f1 integer,f2 boolean,f3 nvarchar,f4 timestamptz ) 的依赖项:

build.gradle

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)