更改主鍵生成策略後報的錯

2022-09-08 23:48:18 字數 596 閱讀 4434

error [org.hibernate.jdbc.abstractbatcher] - exception executing batch:

org.hibernate.stalestateexception: batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 at org.hibernate.jdbc.expectations$basicexpectation.checkbatched(expectations.j**a:85)

caused by: org.hibernate.stalestateexception: batch update returned unexpected r

ow count from update [0]; actual row count: 0; expected: 1

備註:一開始我們使用native資料庫自動生成的主鍵。後改成assigned手動新增主鍵。更改後台**再執行時報的錯。

解決方案:原因是自己的粗心,沒有s**e物件basedao.s**e(carddistribute);,而是呼叫的update方法。

hibernate的主鍵生成策略

1.increment識別符號生成器 由hibernate管理主鍵,自動以遞增的方式生成識別符號 hibernate會先讀取表中的主鍵最大值,然後向表中插入記錄,在max id 的基礎上遞增,增量為1 帶走加1 存在併發問題,所以開發中不用,2.identity識別符號生成器 由底層資料庫負責生成識...

Hibernate的主鍵生成策略

1 自然主鍵 建表的時候,使用物件中本身的屬性作為表的主鍵。2 主鍵 沒有使用物件中的自身的屬性作為表中的主鍵,使用和物件不相關的屬性作為主鍵。注 在建表的時候,建議使用 主鍵,自然主鍵有可能會參與到業務邏輯中,有可能出現重複或者有的時候需要修改,主鍵不能修改,因此自然主鍵就不能使用了。主鍵不應該由...

JPA的主鍵生成策略

所謂的主鍵生成策略就是,自動生成主鍵列值的策略 identity id自增長策略。只能用於支援id自增長的資料庫。id identity就是強制使用id自增長策略,只能用於支援id自增長的資料庫 generatedvalue strategy generationtype.identity colu...