JOOQ 生成的 类 架构默认为 PUBLIC
JOOQ generated classes have schema defaulted to PUBLIC
这是 的后续问题。我正在使用 jooq codegen 从 jpa 实体自动生成 jooq 类 。我计划将 jooq 用作 SQL 查询生成器,并使用 JPA EntityManager 执行实际查询。但是 jooq 正在从模式默认为 PUBLIC.
的实体生成表
例如,如果我的查询必须是
select SCHEMA_A.colA, SCHEMA_A.colB from SCHEMA_A.tableA;
jooq 正在生成
select PUBLIC.colA, PUBLIC.colB from PUBLIC.tableA;
当我触发以下查询时,这会导致查询失败,因为架构无效。
entityManager.createNativeQuery(sqlString).getResultList();
我需要添加什么配置才能使自动生成的代码包含实际的架构名称?
代码生成器:
<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 配置
<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>
<outputSchema/>
元素不能单独存在,必须与<inputSchema/>
元素配对。原因是,如果您省略 <inputSchema/>
元素,那么您数据库中的所有模式都将用于代码生成,并且不清楚独立 <outputSchema/>
元素的含义。
此错误配置可能应该在日志文件中作为警告报告:https://github.com/jOOQ/jOOQ/issues/6186
有关代码生成器的架构映射功能的更多信息,请点击此处:
https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-catalog-and-schema-mapping
注意:这就是 jOOQ 代码生成器的一般行为方式,JPADatabase
在这里似乎有点特殊这一事实并不重要。即使使用 JPA 注释实体,如果您指定 @Table(schema = "...")
,您也可以拥有一个包含多个模式的数据库。例如。
这是
例如,如果我的查询必须是
select SCHEMA_A.colA, SCHEMA_A.colB from SCHEMA_A.tableA;
jooq 正在生成
select PUBLIC.colA, PUBLIC.colB from PUBLIC.tableA;
当我触发以下查询时,这会导致查询失败,因为架构无效。
entityManager.createNativeQuery(sqlString).getResultList();
我需要添加什么配置才能使自动生成的代码包含实际的架构名称?
代码生成器:
<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 配置
<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>
<outputSchema/>
元素不能单独存在,必须与<inputSchema/>
元素配对。原因是,如果您省略 <inputSchema/>
元素,那么您数据库中的所有模式都将用于代码生成,并且不清楚独立 <outputSchema/>
元素的含义。
此错误配置可能应该在日志文件中作为警告报告:https://github.com/jOOQ/jOOQ/issues/6186
有关代码生成器的架构映射功能的更多信息,请点击此处: https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-catalog-and-schema-mapping
注意:这就是 jOOQ 代码生成器的一般行为方式,JPADatabase
在这里似乎有点特殊这一事实并不重要。即使使用 JPA 注释实体,如果您指定 @Table(schema = "...")
,您也可以拥有一个包含多个模式的数据库。例如。