This is a follow up question to this SO Question. I am using jooq codegen for auto generation of jooq classes from jpa entities. I am planning to use jooq as a SQL query builder and execute the actual queries with JPA EntityManager. But jooq is generating the tables from entities with schema defaulted to PUBLIC.
For example if my query has to be
select SCHEMA_A.colA, SCHEMA_A.colB from SCHEMA_A.tableA;
jooq is generating
select PUBLIC.colA, PUBLIC.colB from PUBLIC.tableA;
This is making the query fail when I fire the following query because the schema is invalid.
entityManager.createNativeQuery(sqlString).getResultList();
What configuration do I need to add to make the autogenerated code contain the actual schema name?
Codegen:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.9.1</version>
<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta-extensions</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>com.yaswanth</groupId>
<artifactId>domain</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<!-- Generator parameters -->
<generator>
<database>
<name>org.jooq.util.jpa.JPADatabase</name>
<outputSchema>[SCHEMA_A]</outputSchema>
<properties>
<!-- A comma separated list of Java packages, that contain your entities -->
<property>
<key>packages</key>
<value>com.yaswanth.domain.entity</value>
</property>
</properties>
</database>
<target>
<packageName>com.yaswanth.domain.entity.jooq</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
</plugin>
</plugins>
</build>
jooq spring beans config
<bean id="dslContext" class="org.jooq.impl.DefaultDSLContext">
<constructor-arg ref="jooqConfig" />
</bean>
<bean id="jooqConfig" class="org.jooq.impl.DefaultConfiguration">
<property name="SQLDialect" value="MYSQL" />
<property name="dataSource" ref="myDataSource" />
<property name="settings" ref="settings"/>
</bean>
<bean id="settings" class="org.jooq.conf.Settings">
<property name="renderSchema" value="true" />
</bean>