如何在春季启动时查看架构SQL(DDL)? [英] How to see the schema sql (DDL) in spring boot?
问题描述
如何查看Hibernate生成的DDL SQL,以根据JPA映射构建架构?我正在使用嵌入式HSQL数据库.
How can I see the DDL SQL generated by Hibernate for building the schema from the JPA mappings? I am using the embedded HSQL db.
我尝试了以下操作,但它们都没有在Spring-Boot 1.3.5.RELEASE中工作.
I tried the following and none of them worked in Spring-Boot 1.3.5.RELEASE.
- 将以下内容添加到application.properties文件
- debug = true
- spring.jpa.properties.hibernate.show_sql = true
那些只向我显示Hibernate发出的用于查询的sql.我正在寻找Hibernate发行的DDL模式sql,它具有以下属性:
Those only show me the sql issued by Hibernate for queries. I am looking for the DDL schema sql issued by Hibernate due the following property:
spring.jpa.hibernate.ddl-auto=create-drop
推荐答案
尝试使用此属性和值:
javax.persistence.schema-generation.scripts.action=create
别忘了还要设置此属性:
Do not forget to also set this property:
javax.persistence.schema-generation.scripts.create-target=my-schema.sql
来自 JPA 2.1规范,第370页:
javax.persistence.schema-generation.scripts.action
javax.persistence.schema-generation.scripts.action 属性指定持久性提供程序将生成哪些脚本.这此属性的值是
none
,create
,拖放创建
,drop
.一种仅在指定脚本目标的情况下才会生成脚本.如果未指定此属性,假定脚本生成不需要或不需要The javax.persistence.schema-generation.scripts.action property specifies which scripts are to be generated by the persistence provider. The values for this property are
none
,create
,drop-and-create
,drop
. A script will only be generated if the script target is specified. If this property is not specified, it is assumed that script generation is not needed or will在Spring Boot中,您可以在
application.properties
文件中定义这两个属性:In Spring Boot you can define those two properties in your
application.properties
file:spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=build/my-schema.sql spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
此处是有关JPA模式生成的博客文章,其中包含有关这些属性和其他属性的更多信息: http://www.thoughts-on-java.org/standardized-schema-generation-data-loading-jpa-2-1/
Here is a blog post about JPA schema generation with further information about these and other properties: http://www.thoughts-on-java.org/standardized-schema-generation-data-loading-jpa-2-1/
这篇关于如何在春季启动时查看架构SQL(DDL)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!