3 回答

TA贡献2021条经验 获得超8个赞
如果此处不存在,则添加此属性有效并创建架构
jpaProps.put("javax.persistence.create-database-schemas", true);
hibernate.hbm2dll.create_namespaces 的 JPA 变体。指定除了创建数据库对象(表、序列、约束等)之外,持久性提供程序是否还要创建数据库模式。如果持久性提供程序要在数据库中创建模式或生成包含“CREATE SCHEMA”命令的 DDL,则该布尔属性的值应设置为 true。如果未提供此属性(或明确为 false),则提供者不应尝试创建数据库模式。

TA贡献1827条经验 获得超8个赞
虽然另一个答案是完全正确的,但我正在分享对我有用的东西。如果不存在,将其添加到application.properties文件将创建模式
spring.jpa.properties.hibernate.hbm2dll.create_namespaces=true
这里我们使用带有 Spring JPA 的 Hibernates 原生属性 prefixed(spring.jpa.properties.*)。同样,您可以通过这种方式使用许多其他 Hibernates 原生属性。
您可以使用 spring.jpa.properties.* 设置它以及其他 Hibernate 本机属性(在将它们添加到实体管理器之前去除前缀)。
*就我而言,我使用的是 MSSQL Server

TA贡献1828条经验 获得超13个赞
这对我在 Springboot 2.6.2 上的 Postgres 有用。
如果它不存在,它将创建模式(适配器边界),并在创建所有实体表时将其用作 default_schema。
为记录启用 TRACE 以查看它的工作原理。
spring:
jpa:
open-in-view: false
generate-ddl: true
properties:
javax:
persistence:
schema-generation:
database:
action: create
hibernate:
show_sql: true
use_sql_comments: true
format_sql: true
generate_statistics: false
jdbc:
fetch_size: 2000
lob.non_contextual_creation: true
dialect: org.hibernate.dialect.PostgreSQLDialect
ddl-auto: create
hbm2dll:
create_namespaces: true
default_schema: adapterborder
datasource:
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=adapterborder
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
testWhileIdle: true
hikari:
minimumIdle: 5
maximumPoolSize: 20
idleTimeout: 30000
poolName: SpringBootJPAHikariCP
maxLifetime: 200000
connectionTimeout: 30000
connection-test-query: SELECT 1
logging:
level:
'[org.springframework.data]': TRACE
'[org.hibernate]': TRACE
'[javax.persistence]': TRACE
添加回答
举报