Spring Boot 参考指南读书笔记-75章节数据库初始化
Spring Boot 参考指南读书笔记-75章节数据库初始化
75.2 使用Hibernate初始化数据库 配置属性
spring.jpa.hibernate.ddl-auto
的值包括: none, validate, update, create, create-drop 该属性的默认值取决于框架检测到的数据库连接类型是否为嵌入式数据库 如果为嵌入式数据库,则值为create-drop否则为none
如果你在类路径中放置了数据库初始化脚本文件 schema-${platform}.sql, schema.sql或 data-${platform}.sql,data.sql
为导致数据库被初始化两次
当Spring Boot 检测以上两个文件时会启用JDBC的方式初始化数据库,执行这两个脚本文件 当spring.jpa.hibernate.ddl-auto为的值不为""或"none"时会对数据库再次重建
可能导致数据初化不正确
因此当配置了schema-${platform}.sql, schema.sql或 data-${platform}.sql,data.sql时 要注意将配置属性 spring.jpa.hibernate.ddl-auto 的值设置为""或"none"