gpt4 book ai didi

java - 将自定义 `DataType` 添加到 postgres-enum-typed `Binding` 时,Field 的 `TableField` 发生意外变化

转载 作者:行者123 更新时间:2023-11-29 13:16:57 31 4
gpt4 key购买 nike

我们将 JOOQ 3.7.3 与 Postgres 9.5 结合使用。我们使用 Postgres 的 enum类型并将它们映射到我们自己的(手写的)Java 枚举。到目前为止,JOOQ 元模型如下所示:

TableField<InvoiceAccountingEntryRecord, AccountingTypeEnum> ACCOUNTING_TYPE = 
createField("accounting_type",
org.jooq.util.postgres.PostgresDataType.VARCHAR.asEnumDataType(com.us.app.schema.enums.AccountingTypeEnum.class),
this,
"");

使用 JOOQ 生成的枚举使模式生成变得容易,但我们需要大量显式映射。我们想直接在 JOOQ 模型中使用我们自己的枚举类型,并在 JOOQ 生成器配置中为每个类型定义一个自定义绑定(bind):

<customType>
<name>AccountingTypeEnum</name>
<type>com.us.own.enums.AccountingType</type>
<binding>com.us.own.enums.AccountingType.AccountingTypeJooqBinding</binding>
</customType>
...
<forcedType>
<name>AccountingTypeEnum</name>
<expression>.*ACCOUNTING_TYPE</expression>
</forcedType>

奇怪的是,这不仅会影响 Field 的值类型,还会影响 DataType , 更改为 DefaultDataType.getDefaultDataType("USER-DEFINED") , 一个 DataType<Object> :

TableField<InvoiceAccountingEntryRecord, AccountingType> ACCOUNTING_TYPE = 
createField("accounting_type",
org.jooq.impl.DefaultDataType.getDefaultDataType("USER-DEFINED"),
this,
"",
new AccountingTypeJooqBinding());

这是为什么,我能否确保我得到了 DataType<AccountingTypeEnum>以前用过吗?

最佳答案

经过一些实验,发现这确实是JOOQ的generator中的一个bug,影响3.7.3,但在3.10.3中已经不存在了。是时候升级了!

关于java - 将自定义 `DataType` 添加到 postgres-enum-typed `Binding` 时,Field 的 `TableField` 发生意外变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47749251/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com