如何设置连接属性(包括同义词) [英] How to set connection properties (includeSynonyms)
问题描述
我在Spring Boot中的数据库配置是使用yaml文件完成的:
My DB configuration in Spring Boot is done using yaml file:
# Common
spring:
jpa:
properties:
hibernate:
show_sql: true
use_sql_comments: truecat
format_sql: false
ddl-auto: validate
synonyms: true
connection:
includeSynonyms: true
# CONNECTION_PROPERTY_INCLUDE_SYNONYMS_DEFAULT: 'true'
database: ORACLE
datasource:
tomcat:
max-active: 10
max-idle: 10
# template only
---
spring:
profiles: dev
datasource:
url: jdbc:oracle:thin:@//localhost:1521/DEV
username: DEV
password: ...
最初我是面对
模式验证:缺少表格
Schema-validation: missing table
所以我添加了hibernate.synonyms=true
,现在我得到了
So I added hibernate.synonyms=true
, now I'm getting
模式验证:缺少列
Schema-validation: missing column
要解决此问题,我需要像这样 https://gist.github.com更改连接/uggds/c3f0fa71037bc5177f60
To solve that I'd need to alter connection like this https://gist.github.com/uggds/c3f0fa71037bc5177f60
我可以在配置中这样做吗?
Can I do that in configuration?
我尝试过但没有奏效的东西
What I tried and didn't work
hibernate.connection.CONNECTION_PROPERTY_INCLUDE_SYNONYMS_DEFAULT: true
hibernate.connection.includeSynonyms: true
相关: DatabaseMetaData.getColumns返回同义词的空结果集
我试图用Google搜索,但是什么也没发现...
I tried to google for that, but I found nothing...
基于Deinum的答案的其他测试:
Additional test based on M. Deinum's answer:
我坚信
spring:
jpa:
properties:
hibernate.synonyms: true
和
spring:
jpa:
properties:
hibernate:
synonyms: true
是相同的,至少当我使用另一个时,它具有相同的效果(均导致Schema-validation: missing column
is the same, at least it had the same effect, when I used one or the other (both resulting in Schema-validation: missing column
我添加了
datasource:
tomcat:
max-active: 10
max-idle: 10
connection-properties:
includeSynonyms: true
但是我遇到了同样的错误
but I'm getting the same error
模式验证:缺少列
Schema-validation: missing column
当我完全删除
spring:
jpa:
properties:
hibernate:
synonyms: true
我要
模式验证:缺少表格
Schema-validation: missing table
修改2:
尝试在Hikari连接池上设置属性
Trying setting properties on hikari connection pool
spring:
jpa:
properties:
hibernate:
show_sql: true
use_sql_comments: true
format_sql: false
ddl-auto: validate
synonyms: true
database: ORACLE
datasource:
hikari:
connection-properties:
includeSynonyms: true
我仍然得到:
缺少列[zone_definitionpk_id]
missing column [zone_definitionpk_id]
仅测试一下,当我用view替换同义词时就可以了.另外,当我关闭验证时也可以.我的意思是该功能有效.
Just to test, when I replace synonym with view it's fine. Also when I turn off validation it's fine. I mean the functionality works.
修改3
注意connection-properties
与datasource-properties
的关系,并且使用同义词验证的时间更长(至少对我而言).
Take care of connection-properties
vs. datasource-properties
and with synonyms the validation takes longer (at least for me).
推荐答案
设置hibernate.connection
属性是没有用的.您应该在数据源上设置它们.要设置其他非默认属性,可以使用spring.datasource.tomcat
上的connection-properties
属性.
Setting the hibernate.connection
properties is useless. You should be setting them on the datasource instead. To set additional, non default, properties you can use the connection-properties
property on spring.datasource.tomcat
.
编辑:您不是在使用Tomcat连接池,而是在使用默认的HikariCP.因此,设置tomcat属性几乎没有用.
You aren't using Tomcat connection pool but the default HikariCP. So setting tomcat properties is pretty much useless.
在您的媒体资源中添加以下内容
Adding the following in your properties
spring.datasoure.hikari.datasource-properties.includeSynonyms=true
或yaml
spring:
datasource:
hikari:
datasource-properties:
includeSynonyms: true
您还可以设置相应的休眠属性,但是不这样做.您需要通过spring.jpa.properties
进行设置.这是由于synonyms
没有作为Spring Boot使用的properties对象上的属性公开的事实.因此,您需要将其设置为其他属性.
You could also set the corresponding hibernate property, however not as you do. You need to set it through spring.jpa.properties
. This is due to the fact that the synonyms
isn't exposed as a property on the properties object used by Spring Boot. Hence you need to set it as a additional property.
注意,在本节中使用完整的属性名称hibernate.synonyms
非常重要,请勿将其设置为YAML格式,因为它将不起作用!
NOTE it is importantto use the full property name hibernate.synonyms
in this section, don't format it as YAML as that won't work!.
spring:
jpa:
properties:
hibernate.synonyms: true
编辑(1):由于使用的池是Hikari,而不是Tomcatc更改为Hikari命名空间和属性.
EDIT (1): As the pool used is Hikari and not Tomcatc changed to Hikari namespace and properties.
这篇关于如何设置连接属性(包括同义词)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!