# 79.5 配置JPA属性

Spring Data JPA已经提供了一些独立的配置选项（比如，针对SQL日志），并且Spring Boot会暴露它们，针对Hibernate的外部配置属性也更多些。它们中的一些会通过上下文，被自动探测到，所以你不需要设置它们。

`spring.jpa.hibernate.ddl-auto`比较特殊。因为根据运行条件的不同，它会有不同的默认值。如果使用嵌入式数据库，而没有模式管理器(如Liquibase或Flyway)处理`数据源`，则默认为`create-drop`。在所有其他情况下，它默认为`none`。使用的方言也会基于目前的`数据源`被自动地探测到。但是如果你想要在启动时清楚明白，避开这种选择，你可以自己设置`spring.jpa.database`。

**注** 指定一个`数据库`是配置Hibernate方言的一种很好的方式。多个数据库有多种方言，这可能不符合你的需求。在那种情况下，你既可以把`spring.jpa.database`设置为`default`，来让Hibernate搞定一切，也可以使用`spring.jpa.database-platform`属性来设置方言。

最常见的选项如下：

```
spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy
spring.jpa.show-sql=true
```

此外，当本地的`EntityManagerFactory`被创建时，`spring.jpa.properties.*`里的所有属性会作为正常的JPA属性（前缀除去）被传递。

**注** 如果需要对Hibernate属性应用高级定制，可以考虑注册一个`HibernatePropertiesCustomizer` bean。它将在创建`EntityManagerFactory`之前被调用。这优先于自动配置所应用的任何内容。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/ix.-how-to-guides/79.-data-access/79.5-configure-jpa-properties.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
