【问题标题】:Hibernate is throwing managed flush exceptionHibernate 抛出托管刷新异常
【发布时间】:2019-12-19 23:46:49
【问题描述】:

我们正在尝试在 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]

详细的相关stacktrace如下:

[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 序列,这就是这里的主要气味。

还有 not nullprimary key constraint 在我们试图保存在 DB 上的 Entity 上。

当前的 Hibernate 版本是 Hibernate-core 5.2.17 如果休眠 JPA 为 Hibernate-JPA-2.1-API-1.0.2.Final

,则为版本

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

托管刷新期间出错 [org.hibernate.exception.ConstraintViolationException:

【问题讨论】:

    标签: java oracle hibernate jpa sequence


    【解决方案1】:

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

    检查序列以查看其下一个值是什么,然后检查 USER_FAVORITE 表中此唯一键列的最大值是多少。如果唯一列的最大值 >= 序列中的下一个值,则您必须解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 2015-06-02
      相关资源
      最近更新 更多