【发布时间】: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 null 和 primary 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