简体   繁体   English

JOOQ 将 CHAR OCTETS 列生成为 CHAR 而不是 BINARY

[英]JOOQ generates CHAR OCTETS columns as CHAR instead of BINARY

My problem very close the one mentioned in Using UUID PK or FK in Firebird with Jooq我的问题非常接近使用 Jooq 在 Firebird使用 UUID PK 或 FK 中提到的问题

Setup: Jaybird 3.0.5, Firebird 2.5.7, jOOQ 3.11.7, JDK 1.8设置:Jaybird 3.0.5、Firebird 2.5.7、jOOQ 3.11.7、JDK 1.8

My PK and FK fields like我的 PK 和 FK 字段像

ID CHAR(16) CHARACTER SET OCTETS NOT NULL

and

TABLE_ID CHAR(16) CHARACTER SET OCTETS

and I want to use UUID as java data type in generated classes我想在生成的类中使用 UUID 作为 java 数据类型

I use JDBC connection in configuration like我在配置中使用 JDBC 连接,如

<jdbc>
    <driver>org.firebirdsql.jdbc.FBDriver</driver>
    <url>jdbc:firebirdsql:localhost:c:/DBS/DB.FDB?octetsAsBytes=true</url>
    <properties>
        <property>
            <key>user</key>
            <value>SYSDBA</value>
        </property>
        <property>
            <key>password</key>
            <value>masterkey</value>
        </property>
    </properties>
</jdbc>

I have setup forcedType in generator like我在生成器中设置了 forceType

<forcedType>
    <userType>java.util.UUID</userType>
    <binding>com.ekser.nakkash.icdv.converters.jooq.ByteArray2UUIDBinding</binding>
    <expression>.*ID$</expression>
    <types>CHAR\(16\)</types>
    <nullability>ALL</nullability>
</forcedType>

and I have class我有课

class ByteArray2UUIDBinding implements Binding<byte[], UUID>

Now the problem现在的问题

jOOQ generates jOOQ 生成

public final TableField<MyTableRecord, UUID> ID = createField("ID", org.jooq.impl.SQLDataType.CHAR(16).nullable(false), this, "", new ByteArray2UUIDBinding());

problem is SQLDataType.CHAR(16) , it should be SQLDataType.BINARY(16) .问题是SQLDataType.CHAR(16) ,它应该是SQLDataType.BINARY(16)

jOOQ translate my char(16) octets fields as string ( char(16) ), it does not respect octetsAsBytes=true . jOOQ 将我的char(16) octets字段转换为字符串( char(16) ),它不尊重octetsAsBytes=true

I have tried to put it to properties in <jdbc> like我试图将它放在<jdbc>属性中,例如

<jdbc>
    <driver>org.firebirdsql.jdbc.FBDriver</driver>
    <url>jdbc:firebirdsql:localhost:c:/DBS/DB.FDB</url>
    <properties>
        <property>
            <key>user</key>
            <value>SYSDBA</value>
        </property>
        <property>
            <key>password</key>
            <value>masterkey</value>
        </property>
        <property>
            <key>octetsAsBytes</key>
            <value>true</value>
        </property>
    </properties>
</jdbc>

With the same result.同样的结果。

What is wrong?怎么了? I am considering running search&replace for keyword CHAR(16) -> BINARY(16) in generated classes for now, which is not 'stylish'.我现在正在考虑在生成的类中为关键字CHAR(16) -> BINARY(16)运行搜索和替换,这不是“时尚”。

The setting octetsAsBytes does nothing in Jaybird 3, see Character set OCTETS handled as JDBC (VAR)BINARY in the Jaybird 3 release notes.设置octetsAsBytes在 Jaybird 3 中没有任何作用,请参阅 Jaybird 3 发行说明中的字符集 OCTETS 作为 JDBC (VAR)BINARY 处理 Jaybird 3 always behaves as octetsAsBytes=true in previous versions with some further improvements. Jaybird 3 在以前的版本中始终表现为octetsAsBytes=true并进行了一些进一步的改进。

In other words, this is not related to that setting at all, but is instead a result of how jOOQ generates this.换句话说,这与该设置完全无关,而是 jOOQ 如何生成它的结果。

jOOQ does its own metadata introspection by directly querying the Firebird metadata tables and mapping the Firebird type codes to jOOQ SQL types (see FirebirdTableDefinition and FirebirdDatabase.FIELD_TYPE ). jOOQ 通过直接查询 Firebird 元数据表并将 Firebird 类型代码映射到 jOOQ SQL 类型(请参阅FirebirdTableDefinitionFirebirdDatabase.FIELD_TYPE )来进行自己的元数据内省。 It directly maps Firebird type '15' to CHAR , without further considering subtypes (== character sets for this type).它直接将 Firebird 类型 '15' 映射到CHAR ,而无需进一步考虑子类型(== 此类型的字符集)。

In other words, you'll need to file an improvement ticket with jOOQ if you want to get this mapped to BINARY instead (although it's unclear to me why this is really a problem for you).换句话说,如果您想将其映射到BINARY ,您需要向 jOOQ 提交改进票(尽管我不清楚为什么这对您来说真的是一个问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM