In newer versions of H2, KEY
is a reserved word. JOOQ code generation following this doc fails because we have KEY
as column name in some tables:
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table if not exists FACT_ORDER ([*]KEY varchar not null, ...)"; expected "identifier";
SQL statement:
create table if not exists FACT_ORDER (KEY varchar not null, ...) [42001-214]
Renaming the column is not a feasible solution. The SQL DDL file cannot be edited either as the same file is used by Liquibase.
Tried but not working:
H2 has a configuration command to not consider KEY as a reserved word using SET NON_KEYWORDS KEY
command (H2 doc).
I tried adding the command to the generator, but still am getting the same error:
val target = new Target();
target.setPackageName("com.mycompany.codegen.orderdb");
target.setDirectory(targetPath);
val generator =
new Generator()
.withDatabase(
new Database()
.withName("org.jooq.meta.extensions.ddl.DDLDatabase")
.withProperties(
new Property().withKey("sql").withValue("SET NON_KEYWORDS KEY;"),
new Property().withKey("scripts").withValue(tempDir + "/*.sql"),
new Property().withKey("sort").withValue("alphanumeric")))
.withTarget(target);
val generate = new Generate();
generate.setPojos(true);
generate.setRecords(true);
generate.setPojosEqualsAndHashCode(true);
generate.setFluentSetters(true);
generator.setGenerate(generate);
GenerationTool.generate(
new Configuration().withGenerator(generator).withLogging(getLogLevel()));