org.hibernate.exception.ConstraintViolationException:违反唯一约束条件,求大侠指点

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了org.hibernate.exception.ConstraintViolationException:违反唯一约束条件,求大侠指点相关的知识,希望对你有一定的参考价值。

时不时出现。问题出现后,重启tomcat 后 此问题又消失了。具体错误如下。
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:202)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:91)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:86)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:171)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2048)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2427)
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:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:575)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:662)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
Caused by: java.sql.BatchUpdateException: ORA-00001: 违反唯一约束条件 (NEB.PK_BUDGET)

at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)

<id name="BId" type="java.lang.Long">
<column name="B_ID" precision="22" scale="0" />
<generator class="increment" />
</id>

把原表的数据update,或者修改插入的数据。

1,f003v_0030是确认记录键,可以唯一对应到系统范围内的所有SEMQ实例中的待发送记录,f003v_0030由节点类型,节点id,SEMQ实例id,SEMQ存储id,记录编号组成。tb_0030在f003v_0030上建立唯一索引,可以提高定位速度;

2,运行过程中出现了重复insert导致违反约束的情况,虽然不会造成逻辑错误,但浪费了资源;

3,检查代码发现,在处理接收到的消息时,检查是否已经接收过此消息,即使判定已经接收过,仍先执行insert,出错后检查是否是违反唯一性约束,是则通过f003v_0030定位该记录,获取记录id,该记录id会出现在发送方处理确认消息后的再确认消息中;

4,再确认的目的是告诉接收方"我知道已经送达了",这时才可以安全地清理tb_0030的记录。

参考技术A 检查表中某个字段 是否设置unique = true 然后修改时出现了相同值 参考技术B 表的主键有问题吧,违反唯一性,一般都是表的问题,表里的主键id是唯一的,你是不是有重复的id值本回答被提问者采纳

以上是关于org.hibernate.exception.ConstraintViolationException:违反唯一约束条件,求大侠指点的主要内容,如果未能解决你的问题,请参考以下文章