如何使用 jOOQ 将 Java Instants 映射到带有时区的 H2 TIMESTAMP?

问题描述 投票:0回答:1

使用 Postgres,我可以强制 TIMESTAMPTZ 列映射到带有 jOOQ 映射中强制类型的 Instant

create table if not exists public.items
(
    id           varchar(100) not null,
    modified     timestamptz    not null,
    name         varchar(100) not null,
    "sellByDate" date,
    quality      integer      not null
    );
forcedTypes {
  forcedType {
    name = 'instant'
    includeExpression = '.*'
    includeTypes = 'TIMESTAMPTZ'
  }
}

当我尝试用 H2 做类似的事情时

create table if not exists public.items
(
    id           varchar(100) not null,
    modified     timestamp with time zone   not null,
    name         varchar(100) not null,
    "sellByDate" date,
    quality      integer      not null
    );

forcedTypes {
    forcedType {
        name = 'instant'
        includeExpression = '.*'
        includeTypes = 'TIMESTAMP WITH TIME ZONE'
    }
}

未应用映射

WARNING Unused forced types      : There are unused forced types, which have not been used by this generation run.
This can be because of misconfigurations, such as, for example:
- case sensitive regular expressions
- regular expressions depending on whitespace (Pattern.COMMENTS is turned on!)
- missing or inadequate object qualification
- the object to which the configuration was applied in the past has been dropped
Try turning on DEBUG logging (-X in Maven, --debug in Gradle, and <logging/> in jOOQ) to get additional info about the schema
16:42:53 WARNING Unused forced type       : <priority>0</priority><name>instant</name><autoConverter>true</autoConverter><includeExpression>.*</includeExpression><includeTypes>TIMESTAMP WITH TIME ZONE</includeTypes><nullability>ALL</nullability><objectType>ALL</objectType>

谁能帮忙诊断一下问题吗?

h2 jooq
1个回答
0
投票

警告中的提示:“(Pattern.COMMENTS已打开!)”。这意味着 Java 的

Pattern
类将忽略正则表达式的空格。这对于格式如下的正则表达式通常很有用:

(

# Comment
  SOME_VALUE

# Other comment
| SOME_OTHER_VALUE
)

在这种情况下,您不希望空格(或注释)成为正则表达式的一部分。当然,您不希望将此应用于您的正则表达式,因此请转义空格:

includeTypes = 'TIMESTAMP\\ WITH\\ TIME\\ ZONE'

或者:

includeTypes = 'TIMESTAMP\\sWITH\\sTIME\\sZONE'
© www.soinside.com 2019 - 2024. All rights reserved.