javajooqjooq-codegen-mavenjooq-codegen

jOOQ failure: JPADatabase no entities added


I am trying to generate classes using the Codegen plugin through JPA entity classes that are defined in a dependency. These entity classes have corresponding XML mapping files instead of Annotations. The mapping files (*entity.hbm.xml) are defined elsewhere in another dependency. I have a persistence.xml file in my project that defines the persistence unit and lists all mapping file paths relative to the dependency.

I have included both dependencies in my Maven module. However, the plugin is not able to generate the classes and throws this at me:

[WARNING] No entities added : No entities were added to the MetadataSources This can have several reasons, including: - The packages you've listed do not exist (org.n52.series.db.beans.DataEntity, org.n52.series.db.beans.PlatformEntity, org.n52.series.db.beans.ProcedureEntity, org.n52.series.db.beans.PhenomenonEntity, org.n52.series.db.beans.DatasetEntity, org.n52.series.db.beans.FeatureEntity, org.n52.series.db.beans.sta.HistoricalLocationEntity, org.n52.series.db.beans.sta.LocationEntity, org.n52.series.db.beans.UnitEntity, org.n52.series.db.beans.FormatEntity, org.n52.series.db.beans.parameter.dataset, org.n52.series.db.beans.parameter.procedure, org.n52.series.db.beans.parameter.platform, org.n52.series.db.beans.parameter.observation, org.n52.series.db.beans.parameter.feature, org.n52.series.db.beans.parameter.location, org.n52.series.db.beans.parameter.phenomenon) - The entities in the listed packages are not on the JPADatabase classpath (you must compile them before running jOOQ's codegen, see "how to organise your dependencies" in the manual: https://www.jooq.org/doc/latest/manual/code-generation/codegen-jpa/!)

This is how my build plugins section of the pom.xml looks like:

<build>
        <plugins>
            <plugin>
                <groupId>dev.aspectj</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.13.1</version>
                <configuration>
                    <complianceLevel>17</complianceLevel>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>org.springframework</groupId>
                            <artifactId>spring-aspects</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jooq</groupId>
                <artifactId>jooq-codegen-maven</artifactId>
                <version>3.19.10</version>
                <executions>
                    <execution>
                        <id>generate-h2-jpa</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generator>
                        <database>
                            <name>org.jooq.meta.extensions.jpa.JPADatabase</name>
                            <properties>
                                <property>
                                    <key>persistenceUnitName</key>
                                    <value>default-unit</value>
                                </property>
                                <property>
                                    <key>packages</key>
                                    <value>
                                        org.n52.series.db.beans.DataEntity,
                                        org.n52.series.db.beans.PlatformEntity,
                                        org.n52.series.db.beans.ProcedureEntity,
                                        org.n52.series.db.beans.PhenomenonEntity,
                                        org.n52.series.db.beans.DatasetEntity,
                                        org.n52.series.db.beans.FeatureEntity,
                                        org.n52.series.db.beans.sta.HistoricalLocationEntity,
                                        org.n52.series.db.beans.sta.LocationEntity,
                                        org.n52.series.db.beans.UnitEntity,
                                        org.n52.series.db.beans.FormatEntity,
                                        org.n52.series.db.beans.parameter.dataset,
                                        org.n52.series.db.beans.parameter.procedure,
                                        org.n52.series.db.beans.parameter.platform,
                                        org.n52.series.db.beans.parameter.observation,
                                        org.n52.series.db.beans.parameter.feature,
                                        org.n52.series.db.beans.parameter.location,
                                        org.n52.series.db.beans.parameter.phenomenon
                                    </value>
                                </property>
                            </properties>
                        </database>
                        <target>
                            <packageName>package org.n52.sta.data.cloudnative.schema</packageName>
                            <directory>src/main/java</directory>
                        </target>
                    </generator>
                </configuration>

                <dependencies>
                    <dependency>
                        <groupId>org.jooq</groupId>
                        <artifactId>jooq-meta-extensions-hibernate</artifactId>
                        <version>3.19.10</version>
                    </dependency>
                    <dependency>
                        <groupId>jakarta.persistence</groupId>
                        <artifactId>jakarta.persistence-api</artifactId>
                        <version>3.1.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.n52.sensorweb-server.db-model</groupId>
                        <artifactId>db-model-entities</artifactId>
                        <version>${db-model.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.n52.sensorweb-server.db-model</groupId>
                        <artifactId>db-model-mappings</artifactId>
                        <version>${db-model.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

IntelliJ shows that dependencies are loaded:

dependencies screenshot


Solution

  • There are a few things to mention here:

    You could create a jOOQ feature request to support alternative configuration approaches, including hbm.xml based ones, though there are probably simpler solutions in the short term, including a solution where you extract the DDL using a different approach, and generate code based on that, e.g. by using testcontainers.