我正在使用Postgresql 3.11.12
评估jOOQ 12.0
。这是我的(超级)简单数据库:
--
-- 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);
我有一个Spring Boot项目,该项目使用Flyway来设置数据库(暂时不关心数据种子,例如:INSERT
语句),对于代码生成,我正在使用{{ 1}}(Gradle)插件版本dev.bombinating.jooq-codegen
:
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, "");
,我也会得到几乎相同的结果。
...而且我还遇到其他一些错误,但是这些错误可能与我设置插件设置的方式有关(我想):
.withExcludes("")
有什么办法可以解决这个问题?我已经看到那里的大多数示例都将生成的代码放在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"]
工件由jOOQ
提供(从org.springframework.boot:spring-boot-starter-jooq
Spring BOM推断)。
答案 0 :(得分:2)
spring-boot-starter-jooq(春季启动发行版2.1.9)中的jOOQ版本为3.11.12,而您根据id("dev.bombinating.jooq-codegen").version("3.12.1")
使用codegen版本3.12.1。我们应该确保它们的版本完全相同。
您还可以使用jOOQ version = 3.12.1附带的Spring Boot版本2.2.0。