Hibernate抛异常Could not execute JDBC batch update
来源:互联网 发布:js刷新当前页面的方法 编辑:程序博客网 时间:2024/05/29 17:09
用Hibernate插入数据时(save(...))出现这个异常:
Exception in thread "main" 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:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.smart.TestautoHome.save(TestautoHome.java:127)
at com.smart.test.main(test.java:10)
Caused by: java.sql.BatchUpdateException: 批次处理0insert into public.testauto (name, id) values (smart, 0)失败,调用getNextException查看原因。
at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2533)
at org.postgresql.core.v3.QueryExecutorImpl$1.handleError(QueryExecutorImpl.java:401)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1316)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:349)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2670)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more
发现原来是因为利用Hibernate Tools导出的hbm映射文件中,没有设定对应数据库表的自增主键造成。导出的的hbm文件如下:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2007-9-6 14:54:09 by Hibernate Tools 3.2.0.b10 -->
<hibernate-mapping>
<class name="com.smart.Testauto" table="testauto">
<id name="id" type="int">
<column name="id" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="name" length="50" />
</property>
</class>
</hibernate-mapping>
注意到,数据库里testauto表的主键id是自增的,而在上面的映射文件里是:<generator class="assigned" />
只要把 assigned 改成 increment 就可以了~
- Hibernate抛异常Could not execute JDBC batch update
- Could not execute JDBC batch update异常的解决办法
- org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- hibernate错误:IllegalArgumentException以及Could not execute JDBC batch update
- org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- Hibernate flushing: Could not execute JDBC batch update;
- 小谈Hibernate下SQL Grammer Exception,Could not execute JDBC batch update异常的解决
- Hibernate数据关联映射出现Could not execute JDBC batch update的异常处理
- Could not execute JDBC batch update
- 再说Could not execute JDBC batch update
- SQLGrammarException: Could not execute JDBC batch update
- windows server 2000 密钥过期解决办法
- SQL2005开启选项的一些方法整理
- 最详细的国内各银行收费情况一览
- 教学团队能给高校带来什么
- 怎样使用DataGrid控件
- Hibernate抛异常Could not execute JDBC batch update
- Weka项目中的ARFF文件结构解析
- 从世界杯看软件团队建设和管理
- 给Windows减肥
- 构建Windows Server 2008虚拟测试实验室
- 入侵oracle数据库的一些心得
- Joe的故事
- IT程序员喝酒喝出的计算机文化
- asp.net调用存储过程方法新解