简体   繁体   English

JOOQ-列“ id”的类型为uuid,但表达式的类型为字符变化

[英]JOOQ - column “id” is of type uuid but expression is of type character varying

I'm having an issue related to JOOQ. 我遇到与JOOQ相关的问题。

--------- ---------
This is my "setup" that led to the issue. 这是导致问题的我的“设置”。
Table: 表:

CREATE TABLE "public".xyz
(
  id UUID NOT NULL,
  CONSTRAINT pk_t_xyz PRIMARY KEY(id)
);

Generated field with JOOQ is correct JOOQ生成的字段正确

public final TableField<XYZRecord, UUID> ID = createField("id", org.jooq.impl.SQLDataType.UUID.nullable(false), this, "comment");

UUID is from java.util.* UUID来自java.util.*

My "custom" POJO with UUID from java.util.* : 我的“自定义” POJO具有来自java.util.* UUID:

public class XYZ {

    @NotNull
    private UUID id;

    public XYZ (@NotNull UUID id) {
        this.id = id;
    }

    public UUID getId() {
        return id;
    }
}

DSL configuration: DSL配置:

@Configuration
public class DataSourceConfiguration {

    @Qualifier("dataSource")
    @Autowired
    private DataSource dataSource;

    @Bean
    public DefaultDSLContext dsl() {
        return new DefaultDSLContext(configuration());
    }

    @Bean
    public DataSourceConnectionProvider connectionProvider() {
        return new DataSourceConnectionProvider
            (new TransactionAwareDataSourceProxy(dataSource));
    }

    public DefaultConfiguration configuration() {
        DefaultConfiguration jooqConfiguration = new DefaultConfiguration();
        jooqConfiguration.set(connectionProvider());
        jooqConfiguration.set(new DefaultExecuteListenerProvider(exceptionTransformer()));
        return jooqConfiguration;
    }

    @Bean
    public ExceptionTranslator exceptionTransformer() {
        return new ExceptionTranslator();
    }
}

Datasource in application.yml application.yml中的数据源

spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/xyz-data

Version of jooq is 3.10.5. jooq的版本是3.10.5。 I'm using spring-boot-starter-jooq with spring boot in version 2.0.0.RELEASE . 我在spring-boot-starter-jooq版本2.0.0.RELEASE spring-boot-starter-jooq与spring boot 2.0.0.RELEASE PostgresSQL version is 10. PostgresSQL版本为10。
------------------ ------------------
When I try to insert data like this: 当我尝试像这样插入数据时:

    dslContext.insertInto(XYZ, XYZ.ID)
        .values(xyz.getId()).execute();

It does not work for some reason. 由于某种原因,它不起作用。 As I understand from exception below JOOQ is casting UUID to string and therefore the SQL is invalid. 从下面的异常可以理解,JOOQ正在将UUID强制转换为字符串,因此SQL无效。 Should I write some kind of converter or did I define something in wrong way? 我应该编写某种转换器还是以错误的方式定义某些内容?

Error: 错误:

org.springframework.jdbc.BadSqlGrammarException: Access database using jOOQ; bad SQL grammar [insert into "public"."xyz" ("id") values (?)]; nested exception is org.postgresql.util.PSQLException: ERROR: column "id" is of type uuid but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 225
[...]
Caused by: org.postgresql.util.PSQLException: ERROR: column "id" is of type uuid but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 225
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2422)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2167)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
    at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
    at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
    at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:144)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
    at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:209)
    at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:429)
    at org.jooq.impl.AbstractDMLQuery.execute(AbstractDMLQuery.java:452)
    at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:347)
    ... 51 more

I had this exact issue with Spring Boot. 我在Spring Boot中遇到了这个确切的问题。 I could work around the issue by explicitly specifying the Postgres Dialect when setting up the DefaultConfiguration object. 我可以通过在设置DefaultConfiguration对象时显式指定Postgres方言来解决此问题。

Eg in your DSL configuration: 例如,在您的DSL配置中:

public DefaultConfiguration configuration() {
    DefaultConfiguration jooqConfiguration = new DefaultConfiguration();

    // Explicitly set the Dialect
    jooqConfiguration.setSQLDialect(SQLDialect.POSTGRES);

    jooqConfiguration.set(connectionProvider());
    jooqConfiguration.set(new DefaultExecuteListenerProvider(exceptionTransformer()));
    return jooqConfiguration;
}

This is a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/7351 这是jOOQ中的错误: https//github.com/jOOQ/jOOQ/issues/7351

It seems to happen only when binding null values as UUIDs. 似乎仅当将null值绑定为UUID时才会发生。 The workaround is to implement your own data type binding: https://www.jooq.org/doc/latest/manual/sql-building/queryparts/custom-bindings 解决方法是实现您自己的数据类型绑定: https : //www.jooq.org/doc/latest/manual/sql-building/queryparts/custom-bindings

暂无
暂无

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

相关问题 列是 uuid 类型,但表达式是 Spark Scala 中不同的字符类型 - Column is of type uuid but expression is of type character varying in Spark Scala 当我在 Jooq 中插入日期时,出现此错误:column creation_date is of type timestamp with time zone but expression is of type character varying - When I insert a date in Jooq, I get this error: column creation_date is of type timestamp with time zone but expression is of type character varying java sql error列的类型为整数,但表达式的类型为字符变化 - java sql error column is of type integer but expression is of type character varying 错误:列“id”是 uuid 类型,但表达式是 bytea 类型 - ERROR: column "id" is of type uuid but expression is of type bytea PostgreSQL 提示:您需要重写或转换表达式。 “状态”列的类型是状态,但表达式的类型是字符变化 - PostgreSQL Hint: You will need to rewrite or cast the expression. column “state” is of type status but expression is of type character varying 在 jooq 中为 mysql 自定义 UUID 类型 - Customizing UUID type for mysql in jooq org.postgresql.util.PSQLException:错误:列“标签”是 jsonb 类型,但表达式的类型是字符变化 - org.postgresql.util.PSQLException: ERROR: column "tags" is of type jsonb but expression is of type character varying 错误:列“DOJ”的类型是没有时区的时间戳,但表达式的类型是字符变化 - ERROR: column "DOJ" is of type timestamp without time zone but expression is of type character varying 在字符类型变化的列上使用聚合函数 - Using aggregate function on a column of type character varying 错误: <column-name> 是没有时区的时间,但表达的类型字符是变化的 - Error: the <column-name> is of time without time zone but expression is of type character varying
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM