I am receiving below hibernate error message while flush.I am iterating in a for loop, fetch the object from DB modify it and saves the object in each iteration. It does not give any error for first 20 records. for the next record, it throws below errors. Any suggestions ? Thanks !
WARN [main] (org.hibernate.util.JDBCExceptionReporter:233) - SQL Error: -803, SQLState: 23505
ERROR [main] (org.hibernate.util.JDBCExceptionReporter:234) – DB2 SQL error: SQLCODE: -803, SQLSTATE: 23505, SQLERRMC: 3;REFERN.METHODOLOGY
ERROR [main] (org.hibernate.event.def.AbstractFlushingEventListener:324) – Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not update: [com.MethodologyDO#1396]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2594)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2476)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2803)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.springframework.orm.hibernate3.HibernateTemplate$28.doInHibernate(HibernateTemplate.java:892)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:890)
Googling for the SQLState mentiones in the error led me to the following page: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0sttmsg.htm.
A unique constraint is broken. You’re trying to insert/update data and two rows end up having the same value in a column which has a unique constraint.