Reputation:
I'm evaluating jOOQ 3.11.12
using Postgresql 12.0
. This is my (super) simple database:
--
-- 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);
I have a Spring Boot project that uses Flyway to setup the database (don't mind the data seed for now, e.g.: the INSERT
statements), and for the code generation I'm using the dev.bombinating.jooq-codegen
(Gradle) plugin version 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/") }
}
I can "resolve" (import) and use the generated types: io.shido.codegen.tables.Departments.DEPARTMENTS
, but as soon as I try to run the application I get a bunch of errors like this:
/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.
...and also I'm getting some other errors, but those are probably related with the way I set up the plugin settings (I guess):
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
Is there any way to get around this? I've seen that most of the examples out there put the generated code in sourceSets["main"]
, but I think it should behave the same in the way I configured it.
IMPORTANT: The
jOOQ
artifact is provided byorg.springframework.boot:spring-boot-starter-jooq
(inferred from the2.1.9.RELEASE
Spring BOM).
Upvotes: 0
Views: 2076
Reputation: 1940
The jOOQ version in spring-boot-starter-jooq (spring boot release 2.1.9) is 3.11.12, while you use codegen version 3.12.1 according to id("dev.bombinating.jooq-codegen").version("3.12.1")
. We should ensure they are in the exact same version.
You could also use spring boot release 2.2.0 that comes with jOOQ version=3.12.1.
Upvotes: 2