spring_reference/IX. ‘How-to’ guides/67.5. Configure JPA propert...

13 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 67.5. 配置JPA属性
Spring Data JPA已经提供了一些独立的配置选项比如针对SQL日志并且Spring Boot会暴露它们针对hibernate的外部配置属性也更多些。最常见的选项如下
```java
spring.jpa.hibernate.ddl-auto: create-drop
spring.jpa.hibernate.naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database: H2
spring.jpa.show-sql: true
```
由于宽松的数据绑定策略连字符或下划线作为属性keys作用应该是等效的`ddl-auto`配置是个特殊情况它有不同的默认设置这取决于你是否使用一个内嵌数据库create-drop。当本地EntityManagerFactory被创建时所有`spring.jpa.properties.*`属性都被作为正常的JPA属性去掉前缀传递进去了。
具体参考[HibernateJpaAutoConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java)和[JpaBaseConfiguration](http://github.com/spring-projects/spring-boot/tree/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java)。