1

I want to generate pojos using jooq from two datasources (Two separate MySQL database hosted on separate AWS RDS) in the same spring boot serivce. How can I do that?

I doubt if following can be used here:

jooq {
    DBONE(sourceSets.main) {
        jdbc {
            driver = 'com.mysql.cj.jdbc.Driver'
            url = ...
            user = ...
            password = ...
        }
        generator {
            database {
                includes = '<DB_ONE>.*'
            }
            generate {
                relations = true
                records = true
                pojos = true...
            }
            target {
                packageName = 'com.abcd.jooq'
                directory = 'build/src/generated/java'
            }
        }
    }

    DBTWO(sourceSets.main) {
        jdbc {
            driver = 'com.mysql.cj.jdbc.Driver'
            url = ...
            user = ...
            password = ...
        }
        generator {
            database {
                includes = '<DB_TWO>.*'
            }
            generate {
                relations = true
                records = true
                pojos = true...
            }
            target {
                packageName = 'com.abcd.jooq'
                directory = 'build/src/generated/java'
            }
        }
    }
}

I could notice that only one config.xml could be found after build the spring boot application. And pojos generated for only one datasource. Can any please suggest any to do the same?

Aishwer Sharma
  • 205
  • 2
  • 17

1 Answers1

1

You can't let two generation runs generate code into the same package. Every generation configuration owns its package and will remove everything that doesn't belong there.

You have two options:

  • Use different target packages
  • Use some development code generation data source that allows you to access both databases from the same server, e.g. by using testcontainers (example here), or even the DDLDatabase
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509