66903

jooq codegen with JPADatabase not working

Question:

I have an issue using jooq codegen with JPADatabase. I have gone through this <a href="https://stackoverflow.com/questions/42968155/unable-to-generate-jooq-classes-from-h2-using-jpadatabase" rel="nofollow">post</a> 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.

Answer1:

You seem to have run into issue <a href="https://github.com/jOOQ/jOOQ/issues/5845" rel="nofollow">#5845</a>, 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: <a href="https://github.com/jOOQ/jOOQ/tree/master/jOOQ-meta-extensions" rel="nofollow">https://github.com/jOOQ/jOOQ/tree/master/jOOQ-meta-extensions</a>, or patch your version accordingly.

Answer2:

Following @Lukas Eder's answer, I have tried on the suggestions from <a href="https://github.com/jOOQ/jOOQ/issues/5845" rel="nofollow">#5845</a>. 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!!

Recommend

  • SSIS C# Transform or SQL for separating multiple delimited records into separate rows
  • Doctrine fixtures not working after updating to Symfony 2.1.8
  • Disable Liquibase temporarily in JHipster 2.26
  • Does array_rand use the Mersenne Twister algorithm?
  • auto indent code in html file (generator/tool)?
  • Re-using zip iterator in python 3 [duplicate]
  • Joining tables without relation using JPA criteria
  • How can I convert this tuple of tuples into a count of its elements?
  • jquery:install doesn't work in Rails
  • Scons: create late targets
  • copy data from a mysql database to other mysql database with java
  • Does Java EE 6 framework only for Web Application Or can I use it for Client Application as well
  • Is this hack a defined behavior for T4
  • Passing and ArrayList through intent
  • Plot a CSV file where the delimiter is '; ' (semicolon + space)
  • How to do JOIN ON query using Criteria API
  • How to remove comma or any characters from Python dataframe column name
  • css font-size and line-height not matching the baseline
  • Creating JS objects in PHP with commas in between
  • Is there any purpose for h2-h6 headings in HTML5?
  • Prolog Ambiguous Output
  • Android Database Error - getWriteableDatabase
  • Using Generics on right hand side in Java 6?
  • Javascript, Regex - I need to grab each section of a string contained in brackets
  • Checking if an array in C is symmetric
  • What is the purpose of TaskExecutor in spring?
  • Not able to aggregate on nested fields in elasticsearch
  • how to find common suffix in java by using method
  • gspread or such: help me get cell coordinates (not value)
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Q promise. Difference between .when and .then
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Spring security and special characters
  • How to extract text from Word files using C#?
  • How to check if every primary key value is being referenced as foreign key in another table
  • Sending data from AppleScript to FileMaker records
  • JSON with duplicate key names losing information when parsed
  • Traverse Array and Display in markup
  • C# - Getting references of reference
  • How to get NHibernate ISession to cache entity not retrieved by primary key