【问题标题】:Unable to generate Jooq Classes from H2 using JPADatabase无法使用 JPADatabase 从 H2 生成 Jooq 类
【发布时间】:2017-08-15 12:59:58
【问题描述】:

我目前正在尝试从 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 类。构建的 Stack Trace 显示:

[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 

【问题讨论】:

  • 您的 JPA 注释实体在 jOOQ 代码生成器插件的类路径上吗? IE。它们是在生成 jOOQ 代码之前编译的吗?
  • 没有。它们是插件设置所在的同一模块的一部分。是否应该在运行生成器之前编译?
  • 在运行插件之前使用编译实体对其进行了测试,并且确实有效。非常感谢@LukasEder。您能否将其发布为答案,以便我将其标记为已接受并帮助可能遇到相同问题的其他人?

标签: java jooq


【解决方案1】:

您的实体可能与您放置插件的模块位于同一模块中。这意味着在编译模块之前调用了 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

【讨论】:

    猜你喜欢
    • 2021-01-27
    • 2021-02-20
    • 2019-01-08
    • 2023-03-24
    • 2020-11-14
    • 2019-01-08
    • 2015-09-16
    • 2018-03-07
    • 2017-07-18
    相关资源
    最近更新 更多