我們正在嘗試在 Oracle 中保存實(shí)體:Oracle Database 11g Enterprise Edition Release 11.2.0.3.0我們同樣使用Hibernate :我們收到以下明顯錯(cuò)誤:o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]詳細(xì)的相關(guān)堆棧跟蹤如下:[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 序列來生成主鍵值。我想當(dāng) oracle 序列試圖執(zhí)行時(shí)我們遇到了上述問題。每當(dāng)我們遇到上述異常時(shí),Hibernate 都無法執(zhí)行 Oracle 序列,這是這里的主要問題。我們試圖保存在數(shù)據(jù)庫上的實(shí)體也沒有空值和主鍵約束。當(dāng)前 Hibernate 版本是Hibernate-core 5.2.17 ,如果 hibernate JPA 是Hibernate-JPA-2.1-API-1.0.2.Final 則版本仍然想知道為什么我們得到:托管刷新期間出錯(cuò) [org.hibernate.exception.ConstraintViolationException:
1 回答

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