程式執行至 session.flush() 時拋出 Could not execute JDBC batch update 例外,導致交易失敗。
hibernate.jdbc.batch_size 設定過大,超過資料庫限制(如 Oracle 批次上限)。Caused by: java.sql.BatchUpdateException 之下通常包含具體 SQL 錯誤碼(如 ORA-00001、MySQL 1062)。hibernate.cfg.xml 或 persistence.xml 設定 hibernate.show_sql=true、hibernate.format_sql=true,並將 org.hibernate.SQL 設為 DEBUG 級別。@Column(nullable=false, unique=true) 等約束與資料庫 DDL 一致。hibernate.jdbc.batch_size=20(預設常為 50),或暫時停用批次 hibernate.jdbc.batch_size=0 以縮小問題範圍。session.flush() 前是否已正確 save()/update()/delete(),且無重複操作同一實體導致版本衝突(@Version)。session.flush():將 Session 快取中的異動(insert/update/delete)同步至資料庫,但不清除快取,實體仍處於 managed 狀態。session.clear():完全清除 Session 快取,所有 managed 實體變為 detached。若在 flush() 後立即呼叫 clear(),後續對同一實體的操作需重新 merge() 或 load()。若程式邏輯為「flush 後隨即 clear」,確認是否導致後續操作使用了已 detached 的實體,進而觸發非預期的 SQL。
@SequenceGenerator)。