org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:114)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2411)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2874)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
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:184)
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.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at biz.ProductBiz.addPtype(ProductBiz.java:88)
at servlet.Test.main(Test.java:43)
Caused by: java.sql.BatchUpdateException: ORA-00001: 违反唯一约束条件 (T04.SYS_C0011048)


at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10070)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)

... 16 more


使用hibernate框架,进行级联添加数据时报错,


看到后面的 Caused by: java.sql.BatchUpdateException: ORA-00001: 违反唯一约束条件 (T04.SYS_C0011048)


这是我的商品类型表映射的配置,我用的主键用的是数据库里的序列




seq_ptype






 

 


于是我把数据库的里这个序列使用后发现序列是2,但数据表里的主键已经到了6了,所以应该是再添加测试数据的时候,没有用序列添加,所以才会出现违反唯一约定



我把序列用到7以后,再去执行级联添加,运行正常

你可能感兴趣的:(org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update)