Jooq: Compile error when a schema has the same name as a table within that schema

Created on 13 May 2016  路  5Comments  路  Source: jOOQ/jOOQ

Schemaname: videos
Tablename: videos

Error:
Error:(67, 55) java: variable VIDEOS is already defined in class [package].jooq.videos.Videos

Code Generation Medium Fixed Defect

Most helpful comment

For other people's reference, I solved this problem in 3.8.1 with this configuration:

<plugin>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-codegen-maven</artifactId>

    <configuration>
        <generator>
            <strategy>
                <name>com.mydomain.myproject.jooq.GeneratorStrategy</name>
            </strategy>
        </generator>
    </configuration>
</plugin>

and this class:

public class GeneratorStrategy extends DefaultGeneratorStrategy {
    @Override
    public String getJavaIdentifier(final Definition definition) {
        if (definition instanceof SchemaDefinition) {
            return super.getJavaIdentifier(definition) + "_SCHEMA";
        } else {
            return super.getJavaIdentifier(definition);
        }
    }
}

I unfortunately had to define the java class in a separate package that my dao package depends on, since the GeneratorStrategy wasn't available in the generate-sources phase of the dao project.

All 5 comments

Thank you very much for reporting this. I can reproduce this easily with any database. This is a regression due to https://github.com/jOOQ/jOOQ/issues/4869. Will fix ASAP

Fixed for jOOQ 3.9. This will also go in 3.8.2. Thanks again for reporting!

As a workround, in the meantime, you can use jOOQ's generator strategies to disambiguate the colliding names yourself:

For other people's reference, I solved this problem in 3.8.1 with this configuration:

<plugin>
    <groupId>org.jooq</groupId>
    <artifactId>jooq-codegen-maven</artifactId>

    <configuration>
        <generator>
            <strategy>
                <name>com.mydomain.myproject.jooq.GeneratorStrategy</name>
            </strategy>
        </generator>
    </configuration>
</plugin>

and this class:

public class GeneratorStrategy extends DefaultGeneratorStrategy {
    @Override
    public String getJavaIdentifier(final Definition definition) {
        if (definition instanceof SchemaDefinition) {
            return super.getJavaIdentifier(definition) + "_SCHEMA";
        } else {
            return super.getJavaIdentifier(definition);
        }
    }
}

I unfortunately had to define the java class in a separate package that my dao package depends on, since the GeneratorStrategy wasn't available in the generate-sources phase of the dao project.

Thanks, @ruke47. That is a more thorough solution that doesn't rely on this fixe's internals (which is adding a trailing semicolon for disambiguation)

I prefer to @ruke47 's solution.

Was this page helpful?
0 / 5 - 0 ratings