Caused by: java.sql.BatchUpdateException异常处理

21:32:07,062 ERROR [JDBCExceptionReporter] Duplicate entry 'XXX' for key 3
21:32:07,062 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
	at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
	at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2159)
	at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2595)
	at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:51)
	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
	at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:41)
	at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1562)
	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
	at org.springframework.orm.hibernate3.HibernateTemplate$35.doInHibernate(HibernateTemplate.java:981)
	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:369)
	at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:971)
	at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:964)

       今天工作中遇到了这样一个异常,起初以为memcached缓存的问题,后来,查找数据库数据才发现,原来,重复值的那个字段,做了唯一索引,将该数据删掉后,重新插入数据,一切正常。

 

 

 

你可能感兴趣的:(Java基础)