gpt4 book ai didi

postgresql - 成功生成后jOOQ总是提示 "no suitable method found for createField"

转载 作者:行者123 更新时间:2023-11-29 14:25:34 24 4
gpt4 key购买 nike

我正在使用 Postgresql 12.0 评估 jOOQ 3.11.12。这是我的( super )简单数据库:

--
-- INITIAL DATABASE SETUP
--
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";


--
-- CREATE STATEMENT(S)
--
CREATE TABLE departments
(
id UUID NOT NULL DEFAULT uuid_generate_v4(),
name VARCHAR(20) NOT NULL,

CONSTRAINT pk_department_id PRIMARY KEY (id)
);

CREATE TABLE employees
(
id UUID NOT NULL DEFAULT uuid_generate_v4(),
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,

department_id UUID,

CONSTRAINT pk_employee_id PRIMARY KEY (id),
CONSTRAINT fk_employees_departments_id FOREIGN KEY (department_id) REFERENCES departments (id)
);


--
-- INSERT STATEMENT(S)
--
INSERT INTO departments(id, name)
VALUES ('945079360f314e93a749b1bd83e037bb', 'Clerical'), -- 94507936-0f31-4e93-a749-b1bd83e037bb
('b2759d843e8549c397d9b0ce265c3312', 'Engineering'), -- b2759d84-3e85-49c3-97d9-b0ce265c3312
('cdd1781eb948411ca15f2dfe462ce247', 'Sales'); -- cdd1781e-b948-411c-a15f-2dfe462ce247
INSERT INTO departments(name)
VALUES ('Marketing');

INSERT INTO employees(first_name, last_name, department_id)
VALUES ('Charles', 'Rafferty', '945079360f314e93a749b1bd83e037bb'),
('Joe', 'Armstrong', 'b2759d843e8549c397d9b0ce265c3312'),
('Robert', 'Virding', 'b2759d843e8549c397d9b0ce265c3312'),
('Mike', 'Williams', 'b2759d843e8549c397d9b0ce265c3312'),
('Elizabeth', 'Heisenberg', 'cdd1781eb948411ca15f2dfe462ce247'),
('x80486', 'Williams', NULL);

我有一个使用 Flyway 设置数据库的 Spring Boot 项目(暂时不要介意数据种子,例如:INSERT 语句),以及我正在使用的代码生成dev.bombinating.jooq-codegen (Gradle) 插件版本 3.12.1:

id("dev.bombinating.jooq-codegen").version("3.12.1")

...

configure<JooqExtension> {
val database = Database()
.withExcludes("flyway_schema_history.*|information_schema.*|pg_catalog.*")
.withIncludes(".*")
.withInputSchema("public")
val generate = Generate().withDeprecated(false)
.withFluentSetters(false)
.withImmutablePojos(false)
.withRecords(false)
val target = Target().withDirectory("${project.buildDir}/generated-sources/jooq/")
.withPackageName("${project.group}.codegen") // io.shido.codegen
val jooqVersion: String by project

edition = JooqEdition.OpenSource
generator = Generator().withDatabase(database)
.withGenerate(generate)
.withName("org.jooq.codegen.DefaultGenerator")
.withStrategy(Strategy().withName("org.jooq.codegen.DefaultGeneratorStrategy"))
.withTarget(target)
jdbc = Jdbc().withDriver("org.postgresql.Driver")
.withPassword("postgres")
.withUrl("jdbc:postgresql://localhost:5432/kotlin_spring_boot_jooq")
.withUser("postgres")
version = jooqVersion
}

sourceSets { // TODO: dev.bombinating.jooq-codegen should configure this automatically with sane defaults
main { java.srcDir("${buildDir.absolutePath}/generated-sources/jooq/") }
}

我可以“解析”(导入)并使用生成的类型:io.shido.codegen.tables.Departments.DEPARTMENTS,但是一旦我尝试运行该应用程序,我就会得到一堆像这样的错误:

/home/x80486/Workshop/Development/kotlin-spring-boot-jooq/build/generated-sources/jooq/io/shido/codegen/tables/Departments.java:61: error: no suitable method found for createField(Name,DataType<UUID>,Departments,String)
public final TableField<Record, UUID> ID = createField(DSL.name("id"), org.jooq.impl.SQLDataType.UUID.nullable(false).defaultValue(org.jooq.impl.DSL.field("uuid_generate_v4()", org.jooq.impl.SQLDataType.UUID)), this, "");

...

/home/x80486/Workshop/Development/kotlin-spring-boot-jooq/build/generated-sources/jooq/io/shido/codegen/tables/Departments.java:66: error: no suitable method found for createField(Name,DataType<String>,Departments,String)
public final TableField<Record, String> NAME = createField(DSL.name("name"), org.jooq.impl.SQLDataType.VARCHAR(20).nullable(false), this, "");

NOTE: I get pretty much the same result(s) if I do .withExcludes("") also.

...还有一些其他错误,但这些可能与我设置插件设置的方式有关(我猜):

W o.j.m.AbstractDatabase    - SQL exception            : Exception while executing meta query: ERROR: column c.consrc does not exist
Hint: Perhaps you meant to reference the column "c.conkey" or the column "c.conbin".
Position: 127

有什么办法可以解决这个问题吗?我已经看到那里的大多数示例都将生成的代码放在 sourceSets["main"] 中,但我认为它的行为应该与我配置它的方式相同。

IMPORTANT: The jOOQ artifact is provided by org.springframework.boot:spring-boot-starter-jooq (inferred from the 2.1.9.RELEASE Spring BOM).

最佳答案

spring-boot-starter-jooq(spring boot release 2.1.9)中的jOOQ版本是3.11.12,而你根据id("dev.bombinating.jooq-codegen ").version("3.12.1")。我们应该确保它们的版本完全相同。

您还可以使用 jOOQ version=3.12.1 附带的 spring boot release 2.2.0。

关于postgresql - 成功生成后jOOQ总是提示 "no suitable method found for createField",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58440663/

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