1
我使用jooq生成POJO我H2分貝表JOOQ產生POJO失蹤GeneratedValue註釋
CREATE TABLE PUBLIC.ABC (
ID BIGINT AUTO_INCREMENT PRIMARY KEY,
TRADE_DATE DATE,
STK_CODE VARCHAR(63),
REMARKS TEXT,
TIMESTAMP TIMESTAMP NOT NULL
);
但(下同)
{
...
@Id
@Column(name = "ID", unique = true, nullable = false, precision = 19)
public Long getId() {
return this.id;
}
...
}
缺少生成的代碼@ GeneratedValue註釋,這使得它不可能插入新的記錄與春天的數據休息庫,因爲傳入的對象總是抱怨沒有設置id字段。
什麼配置/變通辦法可以讓jooq正常工作?
下面是相關的POM文件部分我用在編譯時產生的POJO:
<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>
替代方法
最終去了替代品的路線,讓任何低於插件代碼在添加功能之前碰到同樣的問題:
<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>