如果 pojo 和 DAO 在同一个包中,JOOQ 无法生成源

问题描述 投票:0回答:0

我的 pojo(JPA 实体)和 DAO 在同一个包中,我配置了 jooq-codegen-maven 以从 JPA 实体生成 TableImpl 代码。而 DAO 的代码使用了 TableImpl。

奇怪的是,

  1. 当我第一次编译时(

    mvn clean
    install
    ),codegen 将获取 0 表。而且我的 DAO 会出现编译错误(未知类),因为未创建 TableImpl。并且跳过了 JPA 实体(在同一个包中)的编译过程。

  2. 现在,如果我注释掉所有 DAO 代码并编译。 Jooq 也取了 0 个表,但是包的其他代码(包括 9 个 JPA 实体)会编译成功

  3. 我必须再次编译,Jooq 将获取 9 个表,并生成他们的 TableImpl。

  4. 现在我可以取消注释DAO,然后重新编译,最后一切都会成功。 (显然,一个项目编译三次不是一个选项)

如果我换成QueryDSL(使用apt-maven-plugin),它会在第一时间成功。似乎 QueryDSL 首先创建 Q-class 然后编译其他代码,但 Jooq 仅生成代码取决于完全成功的编译,这是不可能的。就像死锁一样。

我的pom.xml:

            <plugin>
                <groupId>com.mysema.maven</groupId>
                <artifactId>apt-maven-plugin</artifactId>
                <version>1.1.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/generated-sources/java</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>



            <plugin>
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <version>${jooq.version}</version>

                <executions>
                    <execution>
                        <id>jooq-codegen</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <generator>
                        <database>
                            <name>org.jooq.meta.extensions.jpa.JPADatabase</name>
                            <inputSchema>PUBLIC</inputSchema>
                            <outputSchemaToDefault>true</outputSchemaToDefault>
                            
                            <properties> 
                                <property>
                                    <key>packages</key>
                                    <value>com.mypack.business</value>
                                </property>
 
                                <property>
                                    <key>useAttributeConverters</key>
                                    <value>true</value>
                                </property> 
                                <property>
                                    <key>unqualifiedSchema</key>
                                    <value>none</value>
                                </property>
                            </properties>
                        </database>
                        <target>
                            <packageName>com.mypack.business.repository.entity.jooq</packageName>
                            <directory>target/generated-sources/java</directory>
                        </target>
                    </generator>
                </configuration>
            </plugin>

那么如何让Jooq一次编译成功呢?

或者,如果有困难,我能不能把pojo和DAO(包括jooq codegen)分散成两个项目来解决?

java maven jooq querydsl jooq-codegen-maven
© www.soinside.com 2019 - 2024. All rights reserved.