自動(dòng)更新表結(jié)構(gòu)
# 開(kāi)發(fā)環(huán)境可使用 update,自動(dòng)更新表結(jié)構(gòu)
spring.jpa.hibernate.ddl-auto=update
# 生產(chǎn)環(huán)境建議使用 none,避免意外修改表結(jié)構(gòu)
spring.jpa.hibernate.ddl-auto=none
顯示 SQL 語(yǔ)句 添加注釋
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
關(guān)閉視圖
# 會(huì)話會(huì)在控制器方法返回后立即關(guān)閉。
# 這要求在控制器方法返回之前完成所有必要的數(shù)據(jù)庫(kù)查詢(xún),避免在視圖渲染階段進(jìn)行數(shù)據(jù)庫(kù)操作。
# 關(guān)閉此模式可以提高性能,減少數(shù)據(jù)庫(kù)連接的占用時(shí)間,同時(shí)也有助于避免延遲加載異常。
spring.jpa.open-in-view=false
UTF-8設(shè)置
# 指定在使用 Hibernate 的 hbm2ddl 工具自動(dòng)創(chuàng)建或更新數(shù)據(jù)庫(kù)表結(jié)構(gòu)時(shí),所使用的字符集
spring.jpa.properties.hibernate.hbm2ddl.charset_name=UTF-8
數(shù)據(jù)庫(kù)生成 按照字段順序
制作 PropertyContainer 類(lèi) 覆蓋
org.hibernate.boot.model.internal.PropertyContainer
修改 76行的代碼
localAttributeMap = new TreeMap<>();
改成
localAttributeMap = new LinkedHashMap<>();
POM 設(shè)置
<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>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。