JOOQ不生成类(JPADatabase) [英] JOOQ does not generating classes (JPADatabase)

查看:71
本文介绍了JOOQ不生成类(JPADatabase)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Spring Boot和Java 8以及JOOQ框架(3.13.5)时遇到问题.我试图按照作者页面上的手册中的说明生成域类(此处中提及.项目结构如下:

I have a problem with JOOQ framework (3.13.5) along with Spring Boot and Java 8. I'm trying to generate domain classes following the instructions from the manual given on the author's page (link) using the GenerationTool from JOOQ, which is mentioned here. The project structure is presented below:

domain 程序包包含JPA实体.然后,我添加了运行配置,作为主要类,我在JOOQ的库中使用了/jooq-config.xml参数标记了 GenerationTool (如上面链接的作者手册中所述).配置文件内容如下所示:

The domain package contains JPA entities. Then I've added run configuration, where as the main class I've marked the GenerationTool from JOOQ's library with argument: /jooq-config.xml (as mentioned in the author's manual linked above). The config file content is shown below:

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
<generator>
    <database>
        <name>org.jooq.meta.extensions.jpa.JPADatabase</name>
        <properties>
            <property>
                <key>packages</key>
                <value>com.ormtester.jpa.domain</value>
            </property>
            <property>
                <key>useAttributeConverters</key>
                <value>true</value>
            </property>
            <property>
                <key>unqualifiedSchema</key>
                <value>none</value>
            </property>
            <property>
                <key>hibernate.physical_naming_strategy</key>
                <value>org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy</value>
            </property>
        </properties>
    </database>
</generator>

对于分析问题,我还要添加带有lib版本的pom.xml片段:

For the analyse issues I'm also adding the the fragment of pom.xml with lib's versions:

<dependencies>
    <dependency>
        <groupId>org.jooq</groupId>
        <artifactId>jooq-meta-extensions</artifactId>
        <version>3.13.5</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>2.3.4.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>${lombok.version}</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.jooq</groupId>
        <artifactId>jooq-codegen</artifactId>
        <version>3.13.5</version>
    </dependency>
</dependencies>

现在,当我尝试构建项目时,出现以下错误:

And now when I'm trying to build the project, I'm getting the following error:

18:49:37.330 [main] WARN org.jooq.util.jaxb.tools.MiniJAXB - org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 72; cvc-elt.1: Cannot find the declaration of element 'configuration'.
18:49:42.215 [main] INFO org.jooq.codegen.GenerationTool - Initialising properties  : /jooq-config.xml
18:49:43.134 [main] DEBUG org.jooq.codegen.GenerationTool - Input configuration      : <onError>FAIL</onError><generator><name>org.jooq.codegen.DefaultGenerator</name><database><name>org.jooq.meta.extensions.jpa.JPADatabase</name><regexMatchesPartialQualification>true</regexMatchesPartialQualification><sqlMatchesPartialQualification>true</sqlMatchesPartialQualification><includes>.*</includes><excludes></excludes><includeExcludeColumns>false</includeExcludeColumns><includeTables>true</includeTables><includeEmbeddables>true</includeEmbeddables><includeRoutines>true</includeRoutines><includeTriggerRoutines>false</includeTriggerRoutines><includePackages>true</includePackages><includePackageRoutines>true</includePackageRoutines><includePackageUDTs>true</includePackageUDTs><includePackageConstants>true</includePackageConstants><includeUDTs>true</includeUDTs><includeSequences>true</includeSequences><includeIndexes>true</includeIndexes><includePrimaryKeys>true</includePrimaryKeys><includeUniqueKeys>true</includeUniqueKeys><includeForeignKeys>true</includeForeignKeys><includeCheckConstraints>true</includeCheckConstraints><includeInvisibleColumns>true</includeInvisibleColumns><recordVersionFields></recordVersionFields><recordTimestampFields></recordTimestampFields><syntheticIdentities></syntheticIdentities><syntheticPrimaryKeys></syntheticPrimaryKeys><overridePrimaryKeys></overridePrimaryKeys><dateAsTimestamp>false</dateAsTimestamp><ignoreProcedureReturnValues>false</ignoreProcedureReturnValues><unsignedTypes>true</unsignedTypes><integerDisplayWidths>true</integerDisplayWidths><inputCatalog></inputCatalog><outputCatalogToDefault>false</outputCatalogToDefault><inputSchema></inputSchema><outputSchemaToDefault>false</outputSchemaToDefault><schemaVersionProvider></schemaVersionProvider><catalogVersionProvider></catalogVersionProvider><orderProvider></orderProvider><forceIntegerTypesOnZeroScaleDecimals>true</forceIntegerTypesOnZeroScaleDecimals><logSlowQueriesAfterSeconds>5</logSlowQueriesAfterSeconds><logSlowResultsAfterSeconds>5</logSlowResultsAfterSeconds><properties><property><key>packages</key><value>com.ormtester.jpa.domain</value></property><property><key>useAttributeConverters</key><value>true</value></property><property><key>unqualifiedSchema</key><value>none</value></property><property><key>hibernate.physical_naming_strategy</key><value>org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy</value></property></properties></database></generator>
Exception in thread "main" java.lang.NoSuchMethodError: org.jooq.meta.jaxb.Configuration.getBasedir()Ljava/lang/String;
    at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:272)
    at org.jooq.codegen.GenerationTool.run(GenerationTool.java:225)
    at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:220)
    at org.jooq.codegen.GenerationTool.main(GenerationTool.java:192)

但是,当我将删除 jooq-config.xml 文件时,该错误会一直告诉我找不到该配置文件.

However when I will remove the jooq-config.xml file then the error is straigtly telling me that the configuration file cannot be found.

我试图调试GenerationTool方法,但是找不到有问题的地方.我无法指定问题的根源,因此,感谢您提供的所有帮助.预先感谢!

I tried to debug the GenerationTool methods but I cannot find the problematic place. I'm unable to designate the source of the problem, so I'll be grateful for every help from Yours side. Thanks in advance!

推荐答案

好吧,按照@Lukas和@Lesiak在本主题中给出的提示,我已经找到了解决方案.正如您在初始pom的内容中看到的那样,我添加了jooq-codegenjooq-meta-extensions并保留了版本3.13.5,并且我确信内幕"是否存在.这些依赖关系持有相同版本的jooqjooq-meta库,但是不幸的是,在两种情况下都存在3.12.3.因此,首先我检查了@Lukas的提示,然后不得不从依赖项中排除这些库,并使用正确的版本号将它们添加为单独的依赖项.

Ok, following the tips given by @Lukas and @Lesiak in this topic I have figured out the solution. As You can see in the initial pom's content I have added the jooq-codegen and jooq-meta-extensions keeping the versions 3.13.5 and I was sure that "under the hood" those depencies are holding the same versions of the jooq and jooq-meta libs but unfortunately there were 3.12.3 in both cases. So firstly I have checked the tips that came from @Lukas and then I had to exclude those libs from from the dependencies and add them as the separate dependencies using the right version numbers.

我也在谈论jooq(最初的问题只在jooq-meta上),因为在解决了Configuration类的问题之后,我也遇到了`org.jooq的类似问题. SQLDialect,如下所示:

I'm also talking about the jooq (where the initial problem was only with jooq-meta) because after the problem with Configuration class has been resolved, I've faced similar problem with `org.jooq.SQLDialect, as following:

java.lang.NoSuchMethodError: org.jooq.SQLDialect.supportedBy([Lorg/jooq/SQLDialect;)Ljava/util/Set; 在org.jooq.meta.AbstractDatabase.(AbstractDatabase.java:117) 在java.lang.Class.forName0(本机方法)在 java.lang.Class.forName(Class.java:264)在 org.jooq.codegen.GenerationTool.loadClass0(GenerationTool.java:983) 在org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:930) 在org.jooq.codegen.GenerationTool.run0(GenerationTool.java:395)处 org.jooq.codegen.GenerationTool.run(GenerationTool.java:225)在 org.jooq.codegen.GenerationTool.generate(GenerationTool.java:220)在 org.jooq.codegen.GenerationTool.main(GenerationTool.java:192)

java.lang.NoSuchMethodError: org.jooq.SQLDialect.supportedBy([Lorg/jooq/SQLDialect;)Ljava/util/Set; at org.jooq.meta.AbstractDatabase.(AbstractDatabase.java:117) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at org.jooq.codegen.GenerationTool.loadClass0(GenerationTool.java:983) at org.jooq.codegen.GenerationTool.loadClass(GenerationTool.java:930) at org.jooq.codegen.GenerationTool.run0(GenerationTool.java:395) at org.jooq.codegen.GenerationTool.run(GenerationTool.java:225) at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:220) at org.jooq.codegen.GenerationTool.main(GenerationTool.java:192)

正如我所说,版本不匹配(在本例中是jooq).

And as I said it also came with the version mismatch, in this case with jooq.

所有这些更改之后,我pom的内容是:

After all those changes my pom's content is:

<dependencies>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.13.5</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta-extensions</artifactId>
            <version>3.13.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq-meta</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>3.13.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>2.3.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.13.5</version>
            <exclusions>
                <exclusion>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.jooq</groupId>
                    <artifactId>jooq-meta</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-tools</artifactId>
            <version>1.3.1</version>
        </dependency>
    </dependencies>

在这里,我可以给您一个小提示-如果您有一个以复数形式命名的表,并且想要快速将它们进行复数化处理以使生成的类的名称保持单数,则必须从pom的代码段中添加最后一个依赖关系,您自己的类,它扩展DefaultGeneratorStrategy并用以下片段覆盖getJavaClassName()方法的主体:

And here I can give You a small hint - if You have a tables named with pluralized form and You want fastly depluralize them to keep names of the generated classes singular, You have to add the last depencency from the pom's snippet, create Your own class that extends DefaultGeneratorStrategy and overvrite the getJavaClassName() method's body with the following fragment:

String javaClassName = super.getJavaClassName(definition, mode);
        boolean hasRecordSuffix = javaClassName.contains("Record");
        javaClassName = javaClassName.replace("Record", "");
        String val = nameTools.depluralize(javaClassName);
        if (hasRecordSuffix)
            val += "Record";
        return val;

然后只需将您的自定义命名策略添加到xml配置中.使用此项目制成的作品就像一个饰物: 链接

Then simply add Your custom naming strategy to the xml config. Works like a charm, made using this project: link

我非常感谢您,@ Lukas和@Lesiak,感谢您的帮助!

I'm really grateful to You, @Lukas and @Lesiak, thanks for this help!

这篇关于JOOQ不生成类(JPADatabase)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆