【发布时间】:2019-05-22 00:33:26
【问题描述】:
我在现有应用中引入spring(hibernate已经有了),遇到了原生SQL查询的问题。
一个示例查询:
SELECT ST_MAKEPOINT(cast(longitude as float), cast(latitude as float)) FROM
OUR_TABLE;
OUR_TABLE 位于 OUR_SCHEMA 中。
当我们将数据库连接到 OUR_SCHEMA 时:
spring.datasource.url: jdbc:postgresql://host:port/db_name?currentSchema=OUR_SCHEMA
查询失败,因为未找到函数 ST_MAKEPOINT - 该函数位于架构中:PUBLIC。
当我们在不指定架构的情况下连接到数据库时,会找到 ST_MAKEPOINT 并正确运行,但需要将架构名称添加到查询中的表名中。
当我们谈论成千上万个这样的查询并且所有表都位于 OUR_SCHEMA 中时,是否有机会指定默认模式,因此来自 PUBLIC 模式的函数仍然可见?
到目前为止,我已经尝试了以下 springboot 属性 - 没有成功:
spring.jpa.properties.hibernate.default_schema: OUR_SCHEMA
spring.datasource.tomcat.initSQL: ALTER SESSION SET CURRENT_SCHEMA=OUR_SCHEMA
spring.datasource.initSQL: ALTER SESSION SET CURRENT_SCHEMA=OUR_SCHEMA
此外,它在切换到 springboot 配置之前工作 - 在 persistence.xml 中指定 hibernate.default-schema = OUR_SCHEMA 就足够了。
堆栈:
弹簧启动:2.0.6
休眠:5.3.1.Final
postgresql:42.2.5
postgis:2.2.1
【问题讨论】:
标签: postgresql hibernate spring-boot postgis