简体   繁体   中英

Hibernate is throwing managed flush exception

We are trying to save entity in Oracle : Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

We are using Hibernate for same:

We are getting following distinct error:

o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]

Detailed relevant stacktrace is as below:

[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"}])"}

We are using oracle sequence for generating primary key value. I guess we are getting above issue when oracle sequence is trying to execute. Hibernate is failing to execute Oracle sequence whenever we get above exception , Thats main smell here.

There is also not null and primary key constraint on Entity that we are trying to save on DB.

Current Hibernate Version is Hibernate-core 5.2.17 and version if hibernate JPA is Hibernate-JPA-2.1-API-1.0.2.Final

Still wondering why we are getting :

Error during managed flush [org.hibernate.exception.ConstraintViolationException:

The important part is the error message which says ORA-00001: unique constraint (XXX.PK_USER_FAVORITE) violated . Apparently the unique constraint on your USER_FAVORITE table is being violated.

Check the sequence to see what its next value is, then check to see what the maximum value of this unique key column in the USER_FAVORITE table is. If the max value of the unique column is >= the next value from the sequence you'll have to fix things up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM