1

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

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>

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 
Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
geneqew
  • 2,401
  • 5
  • 33
  • 48
  • Are your JPA-annotated entities on the classpath of the jOOQ code generator plugin? I.e. are they compiled *before* you generate jOOQ code? – Lukas Eder Mar 23 '17 at 14:17
  • no. they are part of the same module where the plugin settings are in place. Should it be compiled prior to running the generator? – geneqew Mar 24 '17 at 08:16
  • Tested it with a compiled entities prior to running the plugin and it did work. Thanks a bunch @LukasEder. could you post it as an answer so i can mark it as accepted and help other guys who might encounter the same problem? – geneqew Mar 24 '17 at 10:43

1 Answers1

2

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

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

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509