无法使用 JPADatabase 从 H2 生成 Jooq 类

Unable to generate Jooq Classes from H2 using JPADatabase

我目前正在尝试从 jpa 实体而不是使用现有数据库生成 jooq 类。

按照这个 page 并使用 jooq 版本 3.9.1,我当前的 pom 插件部分看起来像

<profile>
            <id>jooq-jpa</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.jooq</groupId>
                        <artifactId>jooq-codegen-maven</artifactId>
                        <version>${jooq.version}</version>

                        <dependencies>
                            <dependency>
                                <groupId>org.jooq</groupId>
                                <artifactId>jooq-meta-extensions</artifactId>
                                <version>${jooq.version}</version>
                            </dependency>
                        </dependencies>

                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>

                        <configuration>
                            <logging>INFO</logging>

                            <generator>
                                <database>
                                    <name>org.jooq.util.jpa.JPADatabase</name>
                                    <includes>.*</includes>
                                    <excludes></excludes>
                                    <properties>
                                        <property>
                                            <key>packages</key>
                                            <value>my.entity</value>
                                        </property>
                                    </properties>
                                </database>
                                <target>
                                    <packageName>com.myentity.jooq</packageName>
                                    <directory>${project.build.directory}/generated-sources/jooq</directory>
                                </target>
                            </generator>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

当 运行 maven 包但未生成预期的 jooq 类 时,这确实会生成成功。构建的堆栈跟踪显示:

[INFO] ARRAYs fetched           : 0 (0 included, 0 excluded)
[INFO] Enums fetched            : 0 (0 included, 0 excluded)
[INFO] Packages fetched         : 0 (0 included, 0 excluded)
[INFO] Routines fetched         : 0 (0 included, 0 excluded)
[INFO] Tables fetched           : 0 (0 included, 0 excluded)
[INFO] UDTs fetched             : 0 (0 included, 0 excluded)
[INFO] Excluding empty catalog  : 
[INFO] Removing excess files 

您的实体可能与您放置插件的模块位于同一模块中。这意味着 jOOQ 代码生成器在编译模块之前被调用,这意味着当 jOOQ 代码生成器试图找到它们时,带有 JPA 注释的实体还没有被编译。

解决方案是创建以下模块依赖关系图:

                        +-------------------+
                        | Your JPA entities |
                        +-------------------+
                             ^         ^
                  depends on |         | depends on
                             |         |
          +---------------------+   +---------------------+
          | jOOQ codegen plugin |   | Your application    |
          +---------------------+   +---------------------+
                             |         |
                   generates |         | depends on
                             v         v
                     +-------------------------+
                     | jOOQ generated classes  |
                     +-------------------------+

我已经注册了一个问题来改进文档以澄清这一点:https://github.com/jOOQ/jOOQ/issues/6011