相关疑难解决方法(0)

如何使用现代Spring Boot + Data JPA和Hibernate设置生成ddl创建脚本?

目前,我正在使用@SpringBootApplication具有以下属性的默认注释application.properties:

spring.datasource.url=jdbc:mysql://localhost/dbname
spring.datasource.username=X
spring.datasource.password=X
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.naming_strategy=my.package.CustomNamingStrategy
Run Code Online (Sandbox Code Playgroud)

从JPA 2.1开始,我应该可以使用这些javax.persistence.schema-generation.*属性,但是在我的application.properties中设置它们似乎没有任何效果.

我见过的例子是这样那丝了一大堆额外的豆子,但他们没有使用MySQL.无论如何,这样做需要我配置春天为我提供的许多选项.

我的目标是:

  • 在MYSQL方言中生成模式创建sql脚本
  • 没有数据库连接是必需的
  • 输出构建目录中的脚本
  • 同时生成hibernate envers表也是一个巨大的优势.

我不想:

  • 在实时数据库上创建/删除模式

Lib版本:

   hibernate          : 4.3.11.FINAL
   spring framework   : 4.2.5.RELEASE
   spring-boot        : 1.3.3.RELEASE
   spring-data-jpa    : 1.10.1.RELEASE   // for  querydsl 4 support
   spring-data-commons: 1.12.1.RELEASE   // for  querydsl 4 support
Run Code Online (Sandbox Code Playgroud)

(使用gradle,而不是maven)

hibernate spring-data spring-data-jpa spring-boot

44
推荐指数
3
解决办法
4万
查看次数