Hibernate引发托管的刷新异常

时间:2019-08-13 12:06:06

标签: java oracle hibernate jpa sequence

我们正在尝试在Oracle中保存实体: Oracle数据库11g 企业版11.2.0.3.0

我们正使用休眠

我们遇到以下明显错误:

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 和版本(如果休眠JPA是 Hibernate-JPA-2.1-API-1.0.2.Final

仍然想知道我们为什么得到:

托管刷新期间发生错误[org.hibernate.exception.ConstraintViolationException:

1 个答案:

答案 0 :(得分:0)

重要的部分是显示ORA-00001: unique constraint (XXX.PK_USER_FAVORITE) violated的错误消息。显然,您的USER_FAVORITE表上的唯一约束已被违反。

检查序列以查看其下一个值是什么,然后检查以查看USER_FAVORITE表中此唯一键列的最大值。如果唯一列的最大值> ==序列中的下一个值,则必须进行修正。