更改Spring Boot使用的数据库模式 [英] Change database schema used by Spring Boot
问题描述
如何指定Spring Boot使用的数据库模式?我使用默认的hibernate(=默认)和postgres(但我希望有一个通用的解决方案)。我知道如何指定JDBC URL:
How do I specify database schema used by Spring Boot? I am using default hibernate (=default) and postgres (but i hoping for a generic solution). I know how to specify JDBC URL:
spring.datasource.url=jdbc:postgresql:db_name
但遗憾的是postgresql不允许在JDBC URL中指定模式。我知道有hibernate属性 hibernate.default_schema
,所以我希望以下属性之一能够正常工作:
But unfortunately postgresql does not allow to specify schema in JDBC URL. I know that there is hibernate property hibernate.default_schema
, so I was hoping that one of the following properties will work:
hibernate.default_schema=schema
spring.hibernate.default_schema=schema
spring.jpa.hibernate.default_schema=raw_page
但遗憾的是,他们似乎都没有任何结果。
But unfortunately neither of them seems to have any result.
推荐答案
使用 spring.jpa.properties.hibernate.default_schema = schema
。
来自Spring Boot参考指南:
From the Spring Boot reference guide:
spring.jpa中的所有属性当创建本地EntityManagerFactory时,.properties。*作为普通的JPA属性传递(带有前缀剥离)
all properties in spring.jpa.properties.* are passed through as normal JPA properties (with the prefix stripped) when the local EntityManagerFactory is created
有关可用属性的完整列表,请参阅http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/ #howto-configure-jpa-properties
For a full list of available properties see http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-configure-jpa-properties
这篇关于更改Spring Boot使用的数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!