我們正在嘗試在 Oracle 中保存實體:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0我們同樣使用Hibernate :我們收到以下明顯錯誤:o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]詳細的相關堆棧跟蹤如下:[ERROR]--- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-00001: unique constraint (XXX.PK_USER_FAVORITE) violated
[WARN ] --- [nio-8080-exec-9] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1, SQLState: 23000
[ERROR] --- [nio-8080-exec-9] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [**org.hibernate.exception.ConstraintViolationException**: could not execute statement]
[ERROR] --- [nio-8080-exec-9] c.mastercard.refarch.aop.ServiceLogging : {"aop_service":"UserFavoritesService", "method":"addCurrentUserFavorite", "type":"failed", "error":"could not execute statement; SQL [n/a]; constraint [XXX.PK_USER_FAVORITE]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement", "args":"(["s029158",{"userFavoriteId":null,"applicationId":"XXX","functionAlphaCode":"SOME vale","title":"Service Report"}])"}我們正在使用oracle 序列來生成主鍵值。我想當 oracle 序列試圖執行時我們遇到了上述問題。每當我們遇到上述異常時,Hibernate 都無法執行 Oracle 序列,這是這里的主要問題。我們試圖保存在數據庫上的實體也沒有空值和主鍵約束。當前 Hibernate 版本是Hibernate-core 5.2.17 ,如果 hibernate JPA 是Hibernate-JPA-2.1-API-1.0.2.Final 則版本仍然想知道為什么我們得到:托管刷新期間出錯 [org.hibernate.exception.ConstraintViolationException:
1 回答

慕田峪7331174
TA貢獻1828條經驗 獲得超13個贊
重要的部分是錯誤消息,它說ORA-00001: unique constraint (XXX.PK_USER_FAVORITE) violated
。顯然違反了您的 USER_FAVORITE 表的唯一約束。
檢查序列以查看其下一個值是什么,然后檢查 USER_FAVORITE 表中此唯一鍵列的最大值是多少。如果唯一列的最大值 >= 序列中的下一個值,則您必須解決問題。
添加回答
舉報
0/150
提交
取消