hibernate错误无法在刷新时同步数据库状态和会话

时间:2012-08-07 10:39:21

标签: hibernate

我在flush时收到下面的hibernate错误消息。我在for循环中迭代,从DB中获取对象修改它并在每次迭代中保存对象。它不会给前20条记录带来任何错误。对于下一条记录,它会抛出错误。有什么建议 ?谢谢!

 WARN [main] (org.hibernate.util.JDBCExceptionReporter:233) - SQL Error: -803, SQLState: 23505

错误[main](org.hibernate.util.JDBCExceptionReporter:234) - DB2 SQL错误:SQLCODE:-803,SQLSTATE:23505,SQLERRMC:3; REFERN.METHODOLOGY 错误[main](org.hibernate.event.def.AbstractFlushingEventListener:324) - 无法将数据库状态与会话同步 org.hibernate.exception.ConstraintViolationException:无法更新:[com.MethodologyDO#1396]         在org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)         在org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)         在org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2594)         在org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2476)         在org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2803)         在org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:113)         在org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)         在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)         在org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)         在org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)         在org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)         在org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)         在org.springframework.orm.hibernate3.HibernateTemplate $ 28.doInHibernate(HibernateTemplate.java:892)         在org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)         在org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)         在org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:890)

1 个答案:

答案 0 :(得分:1)

在错误中搜索SQLState提及,引导我进入以下页面:http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0sttmsg.htm

一个独特的约束被打破。您正在尝试插入/更新数据,并且两行最终在具有唯一约束的列中具有相同的值。