无法使用JPADatabase从H2生成Jooq类 [英] Unable to generate Jooq Classes from H2 using JPADatabase

查看:81
本文介绍了无法使用JPADatabase从H2生成Jooq类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im currently trying to generate jooq classes from jpa entities instead of using an existing db.

页面并使用jooq版本3.9.1,我当前的pom插件部分看起来像

Following this page and using jooq version 3.9.1, my current pom's plugin section looks like

<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类。构建的堆栈跟踪显示:

This does generates a success when running maven package but expected jooq classes are not generated. Stack Trace of the build shows:

[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 entities are probably located in the same module as where you put the plugin. This means that the jOOQ code generator is called prior to compiling the module, which means that the JPA-annotated entities are not yet compiled when the jOOQ code generator tries to find them.

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

The solution is to create the following module dependency graph:

                        +-------------------+
                        | 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

I've registered an issue to improve the documentation in order to clarify this: https://github.com/jOOQ/jOOQ/issues/6011

这篇关于无法使用JPADatabase从H2生成Jooq类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆