jooq codegen with JPADatabase not working

寵の児 提交于 2019-12-24 09:29:54

问题


I have an issue using jooq codegen with JPADatabase. I have gone through this post and made the changes accordingly. My project contains sub modules and the entity classes are in domain module. I have biz module on which depends on domain. So I have this build configuration in biz module's pom.xml.

<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>3.9.1</version>

            <!-- The plugin should hook into the generate goal -->
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>

            <dependencies>
                <dependency>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq-meta-extensions</artifactId>
                    <version>3.9.1</version>
                </dependency>
            </dependencies>

            <configuration>

                <!-- Generator parameters -->
                <generator>

                    <database>
                        <name>org.jooq.util.jpa.JPADatabase</name>
                        <properties>
                            <!-- A comma separated list of Java packages, that contain your entities -->
                            <property>
                                <key>packages</key>
                                <value>com.yaswanth.domain.entity</value>
                            </property>
                        </properties>
                    </database>

                    <target>
                        <packageName>com.yaswanth.domain.entity.jooq</packageName>
                        <directory>target/generated-sources/jooq</directory>
                    </target>
                </generator>
            </configuration>
        </plugin>
    </plugins>
</build>

The plugin fails with ClassNotFoundException on the entities. This is the stack trace.

Caused by: org.jooq.exception.DataAccessException: Error while exporting schema
    at org.jooq.util.jpa.JPADatabase.create0(JPADatabase.java:147)
    at org.jooq.util.AbstractDatabase.create(AbstractDatabase.java:221)
    at org.jooq.util.AbstractDatabase.create(AbstractDatabase.java:213)
    at org.jooq.util.AbstractDatabase.getDialect(AbstractDatabase.java:195)
    at org.jooq.util.AbstractGenerator.logDatabaseParameters(AbstractGenerator.java:129)
    at org.jooq.util.JavaGenerator.generate(JavaGenerator.java:243)
    at org.jooq.util.GenerationTool.run(GenerationTool.java:610)
    at org.jooq.util.GenerationTool.generate(GenerationTool.java:199)
    at org.jooq.util.maven.Plugin.execute(Plugin.java:188)
    ... 22 more
Caused by: java.lang.ClassNotFoundException: com.walmartlabs.sc.domain.entity.ItemNames
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.jooq.util.jpa.JPADatabase.create0(JPADatabase.java:135)
    ... 30 more

The domain module classes have already been generated but still the plugin says ClassNotFoundException. I am using jooq version 3.9.1. Can anyone tell me what am I doing wrong here?

Update: Lukas Eder's answer is correct answer and accepted one. My own answer for this question worked for me because I had that specific version cached in the maven repo. My answer is wrong.


回答1:


You seem to have run into issue #5845, which is fixed for jOOQ 3.10 and is scheduled for 3.9.3 and 3.8.8.

The best workaround right now might be to use the GitHub version (3.10-SNAPSHOT) of the jooq-meta-extensions dependency: https://github.com/jOOQ/jOOQ/tree/master/jOOQ-meta-extensions, or patch your version accordingly.




回答2:


Following @Lukas Eder's answer, I have tried on the suggestions from #5845. The following build configuration works.

<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>3.9.1</version>

        <!-- The plugin should hook into the generate goal -->
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>

        <dependencies>
            <dependency>
                <groupId>org.jooq</groupId>
                <artifactId>jooq-meta-extensions</artifactId>
                <version>3.9.1</version>
            </dependency>

             <!-- 

              This needs to be the dependency where the entity classes reside. 
              In my case, it is in the same module as the build profile is present.
              Hence the version is ${project.version}
             -->
            <dependency>
                <groupId>com.yaswanth</groupId>
                <artifactId>domain</artifactId>
                <version>${project.version}</version>
            </dependency>  
        </dependencies>
        <configuration>

            <!-- Generator parameters -->
            <generator>

                <database>
                    <name>org.jooq.util.jpa.JPADatabase</name>
                    <properties>
                        <!-- A comma separated list of Java packages, that contain your entities -->
                        <property>
                            <key>packages</key>
                            <value>com.yaswanth.domain.entity</value>
                        </property>
                    </properties>
                </database>

                <target>
                    <packageName>com.yaswanth.domain.entity.jooq</packageName>
                    <directory>target/generated-sources/jooq</directory>
                </target>
            </generator>
        </configuration>
    </plugin>
</plugins>

The weird thing about this configuration is that I am including the module as a dependency in a plugin in build profile of it's own POM!!



来源:https://stackoverflow.com/questions/43760284/jooq-codegen-with-jpadatabase-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!