jOOQ icon indicating copy to clipboard operation
jOOQ copied to clipboard

`AbstractSpringDAOImpl` imported from wrong package

Open blaenk opened this issue 3 years ago • 2 comments

Expected behavior

Given this configuration:

<configuration>
    <jdbc>
        <driver>org.postgresql.Driver</driver>
        <url>${db.url}</url>
        <user>${db.username}</user>
        <password>${db.password}</password>
    </jdbc>
    <generator>
        <generate>
            <!-- Generate the DAO classes -->
            <daos>true</daos>

            <!-- Annotate DAOs (and other types) with spring annotations, such as @Repository and @Autowired
                 for auto-wiring the Configuration instance, e.g. from Spring Boot's jOOQ starter -->
            <springAnnotations>true</springAnnotations>

            <!-- Generate Spring-specific DAOs containing @Transactional annotations -->
            <springDao>true</springDao>
        </generate>
        <target>
            <packageName>jip.app.api.jooq</packageName>
            <directory>src/main/java</directory>
        </target>
        <database>
            <schemata>
                <schema>
                    <inputSchema>app</inputSchema>
                </schema>
                <schema>
                    <inputSchema>bot</inputSchema>
                </schema>
                <schema>
                    <inputSchema>puzzles</inputSchema>
                </schema>
                <schema>
                    <inputSchema>workouts</inputSchema>
                </schema>
            </schemata>
        </database>
    </generator>
</configuration>

I expect for example class jip.app.api.jooq.puzzles.tables.daos.SourcesDao to import AbstractSpringDAOImpl correctly.

Actual behavior

jip.app.api.jooq.puzzles.tables.daos.SourcesDao imports AbstractSpringDAOImpl incorrectly, It expects it within each "schema" package e.g. jip.app.api.jooq.puzzles.AbstractSpringDAOImpl, but checking my source files, it appears that AbstractSpringDAOImpl is actually available at the "package root" jip.app.api.jooq.AbstractSpringDAOImpl.

Here's the beginning of one such DAO file which imports it incorrectly:

package jip.app.api.jooq.puzzles.tables.daos;


import java.util.List;
import java.util.Optional;
import java.util.UUID;

import jip.app.api.jooq.puzzles.AbstractSpringDAOImpl;
import jip.app.api.jooq.puzzles.tables.Sources;
import jip.app.api.jooq.puzzles.tables.records.SourcesRecord;

import org.jooq.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

Steps to reproduce the problem

  • If the problem relates to code generation, please post your code generation configuration
<configuration>
    <jdbc>
        <driver>org.postgresql.Driver</driver>
        <url>${db.url}</url>
        <user>${db.username}</user>
        <password>${db.password}</password>
    </jdbc>
    <generator>
        <generate>
            <!-- Generate the DAO classes -->
            <daos>true</daos>

            <!-- Annotate DAOs (and other types) with spring annotations, such as @Repository and @Autowired
                 for auto-wiring the Configuration instance, e.g. from Spring Boot's jOOQ starter -->
            <springAnnotations>true</springAnnotations>

            <!-- Generate Spring-specific DAOs containing @Transactional annotations -->
            <springDao>true</springDao>
        </generate>
        <target>
            <packageName>jip.app.api.jooq</packageName>
            <directory>src/main/java</directory>
        </target>
        <database>
            <schemata>
                <schema>
                    <inputSchema>app</inputSchema>
                </schema>
                <schema>
                    <inputSchema>bot</inputSchema>
                </schema>
                <schema>
                    <inputSchema>puzzles</inputSchema>
                </schema>
                <schema>
                    <inputSchema>workouts</inputSchema>
                </schema>
            </schemata>
        </database>
    </generator>
</configuration>
``

- If the problem relates to upgrades, please check if your RDBMS version is still supported by jOOQ: https://www.jooq.org/download/support-matrix
- A complete set of DDL statements can help re-create the setup you're having
- An MCVE can be helpful to provide a complete reproduction case: https://github.com/jOOQ/jOOQ-mcve

### Versions

- jOOQ: 3.17.2
- Java: 1.18
- Database (include vendor): PostgreSQL 14.1
- OS: Windows
- JDBC Driver (include name if unofficial driver): `org.postgresql.postgresql`

blaenk avatar Jul 10 '22 21:07 blaenk

I may be way off here, but it appears like the file is written out relative to the "catalog parent file", which if I understand correctly, the "catalog" is higher-level than the schema:

https://github.com/jOOQ/jOOQ/blob/3d475fe3267bd2b14b7fe88264088346e84f2f54/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java#L4389

But then the import does so relative to the schema:

https://github.com/jOOQ/jOOQ/blob/3d475fe3267bd2b14b7fe88264088346e84f2f54/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java#L4679

blaenk avatar Jul 10 '22 21:07 blaenk

Thanks a lot for your detailed report. I'll have a look at this soon.

lukaseder avatar Jul 13 '22 19:07 lukaseder

Looking into this now. Indeed, the reference should not use the schema for the qualification, but the catalog.

lukaseder avatar Aug 15 '22 11:08 lukaseder

Fixed in jOOQ 3.18.0 and 3.17.3 (https://github.com/jOOQ/jOOQ/issues/13863)

lukaseder avatar Aug 15 '22 11:08 lukaseder

Thank you Lukas!

blaenk avatar Aug 16 '22 06:08 blaenk