java - JOOQ generated pojo missing GeneratedValue annotation -
i'm using jooq generate pojo h2 db table
create table public.abc ( id bigint auto_increment primary key, trade_date date, stk_code varchar(63), remarks text, timestamp timestamp not null );
but generated code (below)
{ ... @id @column(name = "id", unique = true, nullable = false, precision = 19) public long getid() { return this.id; } ... }
is missing @generatedvalue annotation makes impossible insert new record spring data rest repository since passed in object complain id field not being set.
what config/work around can jooq working properly?
below relevant pom file section used generate pojo @ compile time:
<plugin> <groupid>org.jooq</groupid> <artifactid>jooq-codegen-maven</artifactid> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupid>com.h2database</groupid> <artifactid>h2</artifactid> <version>${h2.version}</version> </dependency> </dependencies> <configuration> <!-- jdbc connection parameters --> <jdbc> <driver>org.h2.driver</driver> <url>jdbc:h2:${user.home}/</url> </jdbc> <!-- generator parameters --> <generator> <database> <name>org.jooq.util.h2.h2database</name> <includes>.*</includes> <schemata> <schema> <inputschema>public</inputschema> </schema> </schemata> </database> <target> <packagename>org.abc</packagename> <directory>target/generated-sources/jooq</directory> </target> <generate> <pojos>true</pojos> <jpaannotations>true</jpaannotations> </generate> </generator> </configuration> </plugin>
workaround
end going replacer route, plugin code below running same issues before feature's added:
<plugin> <groupid>com.google.code.maven-replacer-plugin</groupid> <artifactid>replacer</artifactid> <version>1.5.3</version> <executions> <execution> <phase>prepare-package</phase> <goals> <goal>replace</goal> </goals> </execution> </executions> <configuration> <basedir>${project.basedir}/${jooq.gen.dir}</basedir> <filestoinclude>tables/pojos/*.java</filestoinclude> <replacements> <replacement> <token>@id</token> <value>@id @javax.persistence.generatedvalue</value> </replacement> </replacements> </configuration> </plugin>
as of jooq 3.7, that's missing feature. see: https://github.com/jooq/jooq/issues/5009
you have several workaround options:
- patch generated code using search-replace maven plugin replacing
@id
@id @javax.persistence.generatedvalue(javax.persistence.generationtype.identity)
(assuming primary keysauto_increment
) - patch jooq-codegen's
javagenerator
'sorg.jooq.util.javagenerator.printcolumnjpaannotation()
method , add code yourself.
Comments
Post a Comment