自动更新表结构
# 开发环境可使用 update,自动更新表结构
spring.jpa.hibernate.ddl-auto=update
# 生产环境建议使用 none,避免意外修改表结构
spring.jpa.hibernate.ddl-auto=none
显示 SQL 语句 添加注释
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# 添加注释
spring.jpa.properties.hibernate.use_sql_comments=true
批量操作 配置批量操作的大小
spring.jpa.properties.hibernate.jdbc.batch_size=50
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
关闭视图
# 会话会在控制器方法返回后立即关闭。
# 这要求在控制器方法返回之前完成所有必要的数据库查询,避免在视图渲染阶段进行数据库操作。
# 关闭此模式可以提高性能,减少数据库连接的占用时间,同时也有助于避免延迟加载异常。
spring.jpa.open-in-view=false
UTF-8设置
# 指定在使用 Hibernate 的 hbm2ddl 工具自动创建或更新数据库表结构时,所使用的字符集
spring.jpa.properties.hibernate.hbm2ddl.charset_name=UTF-8
数据库生成 按照字段顺序
制作 PropertyContainer 类 覆盖
org.hibernate.boot.model.internal.PropertyContainer
修改 76行的代码
localAttributeMap = new TreeMap<>();
改成
localAttributeMap = new LinkedHashMap<>();
POM 设置
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.5.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>6.0.6.Final</version>
</dependency>