spring_reference/IV. Spring Boot features/28.3.3. Creating and droppi...

10 lines
1.0 KiB
Markdown
Raw Normal View History

### 28.3.3. 创建和删除JPA数据库
默认情况下只有在你使用内嵌数据库H2, HSQL或DerbyJPA数据库才会被自动创建。你可以使用spring.jpa.*属性显示的设置JPA。比如为了创建和删除表你可以将下面的配置添加到application.properties中
```java
spring.jpa.hibernate.ddl-auto=create-drop
```
**注**Hibernate自己内部对创建删除表支持如果你恰好记得这回事更好的属性是hibernate.hbm2ddl.auto。使用spring.jpa.properties.*前缀在被添加到实体管理器之前会被剥离掉你可以设置Hibernate本身的属性比如hibernate.hbm2ddl.auto。示例`spring.jpa.properties.hibernate.globally_quoted_identifiers=true`将传递hibernate.globally_quoted_identifiers到Hibernate实体管理器。
默认情况下DDL执行或验证被延迟到ApplicationContext启动。这也有一个spring.jpa.generate-ddl标识如果Hibernate自动配置被激活那该标识就不会被使用因为ddl-auto设置粒度更细。