简体   繁体   中英

Spring JOOQ generation partly fails

I'm new to JOOQ and having a problem generating the classes. I have the following Spring configuration pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.knodeit</groupId>
    <artifactId>try</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>try</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq</artifactId>
            <version>3.7.4</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-meta</artifactId>
            <version>3.7.4</version>
        </dependency>
        <dependency>
            <groupId>org.jooq</groupId>
            <artifactId>jooq-codegen</artifactId>
            <version>3.7.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

    <profiles>

        <profile>
            <id>mysql</id>
            <build>
                <plugins>
                    <plugin>

                        <groupId>org.jooq</groupId>
                        <artifactId>jooq-codegen-maven</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>generate</goal>
                                </goals>
                            </execution>
                        </executions>
                        <dependencies>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>${mysql.version}</version>
                            </dependency>
                        </dependencies>
                        <configuration>
                            <jdbc>
                                <driver>com.mysql.jdbc.Driver</driver>
                                <url>jdbc:mysql://localhost:3306</url>
                                <user>root</user>
                                <password>root</password>

                            </jdbc>
                            <generator>
                                <name>org.jooq.util.JavaGenerator</name>
                                <database>
                                    <name>org.jooq.util.mysql.MySQLDatabase</name>
                                    <includes>.*</includes>
                                    <excludes />
                                    <inputSchema>demo</inputSchema>
                                </database>
                                <generate>
                                    <relations>true</relations>
                                    <deprecated>false</deprecated>
                                    <instanceFields>true</instanceFields>
                                    <generatedAnnotation>true</generatedAnnotation>
                                    <records>true</records>
                                    <pojos>true</pojos>
                                    <immutablePojos>false</immutablePojos>
                                    <interfaces>true</interfaces>
                                    <daos>true</daos>
                                    <jpaAnnotations>true</jpaAnnotations>
                                    <validationAnnotations>true</validationAnnotations>
                                    <springAnnotations>true</springAnnotations>
                                    <globalObjectReferences>true</globalObjectReferences>
                                    <fluentSetters>false</fluentSetters>
                                </generate>
                                <target>
                                    <packageName>com.knodeit.jooq.domain</packageName>
                                    <directory>jooq</directory>
                                </target>
                            </generator>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>


</project>

When I run mvn clean install -P mysql it connects to the database and generates a bunch of classes under the jooq folder as configured. However after that i see a ton of errors like:

[ERROR] /Users/petervandeput/Documents/Development/test/try/jooq/com/knodeit/jooq/domain/tables/records/BookRecord.java:[76,25] cannot find symbol
[ERROR] symbol:   method get(int)
[ERROR] location: class com.knodeit.jooq.domain.tables.records.BookRecord
[ERROR] /Users/petervandeput/Documents/Development/test/try/jooq/com/knodeit/jooq/domain/tables/records/BookRecord.java:[210,9] cannot find symbol
[ERROR] symbol:   method set(int,java.lang.Integer)
[ERROR] location: class com.knodeit.jooq.domain.tables.records.BookRecord
[ERROR] /Users/petervandeput/Documents/Development/test/try/jooq/com/knodeit/jooq/domain/tables/records/BookRecord.java:[211,9] cannot find symbol
[ERROR] symbol:   method set(int,java.lang.String)

Can someone provide a 100% working pom.xml that connects to a schema on MySql and generates as it should?

Your generated code targets jOOQ 3.8 (where there is a Record.get(int) method, for instance).

In your dependencies, you're referencing jOOQ 3.7, though, which doesn't have this method yet.

Your jOOQ code generator version and your jOOQ runtime version must match. There are two solutions to this:

  1. Remove the reference to version 3.7.4 from your dependencies, and use the version referenced from Spring Boot, instead
  2. Explicitly set version 3.7.4 also as your code generation version (you currently omitted it)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM