2

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.

Community
  • 1
  • 1
yaswanth
  • 2,349
  • 1
  • 23
  • 33
  • Did you put your entities in a dependency of the module that uses the jOOQ code generator? See: http://stackoverflow.com/q/42968155/521799 – Lukas Eder May 03 '17 at 14:26
  • Yes. The domain module is a dependency in the biz module where the code generation occurs. – yaswanth May 03 '17 at 14:27

2 Answers2

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.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • would it help if I downgraded to 3.8.0? – yaswanth May 03 '17 at 15:34
  • @yaswanth: No, why? It's not a regression. This issue has been with the `JPADatabase` since its first implementation. – Lukas Eder May 03 '17 at 19:35
  • I thought the classloader issue was a bug that started to occur in the later versions. – yaswanth May 04 '17 at 04:29
  • @yaswanth: Hmm, not sure - it was reported only recently. I suspect, older versions are also affected, but this hasn't been tested yet. – Lukas Eder May 04 '17 at 06:02
  • I was just curious. Anyway the other answer I wrote for this question works. Do you think that is a better solution right now? I mean to ask is that going to have any side effects. – yaswanth May 04 '17 at 06:05
  • I'm surprised yours works :) Aah, the bliss of Maven dependency class loading. Yes, a better solution might be to patch your version with the suggested fix - but then again, if yours seems to work, you can also wait for 3.10/3.9.3/3.8.8 – Lukas Eder May 04 '17 at 06:07
1

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

yaswanth
  • 2,349
  • 1
  • 23
  • 33