- 浏览: 2290183 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (357)
- J2EE (49)
- JavaScript (40)
- Spring (19)
- Struts (5)
- CSS (8)
- Hibernate (16)
- Java (67)
- DWR (4)
- JSON (3)
- XFIRE (1)
- Tomcat (1)
- Ant (2)
- 设计模式 (2)
- 经典收藏 (2)
- JSP (10)
- Linux (0)
- WebLogic (11)
- myeclipse (13)
- Buffalo (4)
- 文件上传相关 (1)
- oracle (33)
- html (6)
- JSTL (3)
- SVN (2)
- GIT (1)
- 孙卫琴(Java网络编程精解) (1)
- DOM4J (2)
- Swing (1)
- AJAX (1)
- Eclipse (5)
- 日志组件 (3)
- PowerDesigner (1)
- Jquery (22)
- IT技术开发相关网址 (1)
- Nutz (1)
- 其它 (1)
- Velocity (3)
- WebService (1)
- MySql (2)
- Android (1)
- Maven (2)
- Quartz (11)
- Lucene (1)
- springsource (1)
- Junit (1)
- Activiti (0)
最新评论
-
yzlseu:
拼凑,没有营养
Activiti进阶—分配组任务 -
zhangsenhao:
非常赞!代码很清楚
SpringMVC3.0+MyIbatis3.0(分页示例) -
xiamw2000:
分页写得不对,应该是 : order by ${orderNa ...
SpringMVC3.0+MyIbatis3.0(分页示例) -
sheertewtw:
...
SpringMVC:上传与下载 -
kingtoon:
...
XSS之xssprotect
参考资料
SSH+Oracle问题:org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
http://blog.csdn.net/wearegouest/archive/2010/07/04/5712385.aspx
Could not execute JDBC batch update
http://blog.163.com/leo_canton/blog/static/902931232008101610558474/
Err:Could not execute JDBC batch update
http://apps.hi.baidu.com/share/detail/19115426
一 环境:W7+Eclipse3.6+Mysql5+Hibernate3.6
二 报错如下:
17:52:03,252 WARN JDBCExceptionReporter:233 - SQL Error: 1062, SQLState: 23000
17:52:03,253 ERROR JDBCExceptionReporter:234 - Duplicate entry '1' for key 'PRIMARY'
17:52:03,255 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [org.hibernate.model.Student]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2436)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
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 org.hibernate.model.Test.main(Test.java:25)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2416)
... 11 more
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not insert: [org.hibernate.model.Student]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2436)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
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 org.hibernate.model.Test.main(Test.java:25)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2416)
... 11 more
三 相关代码如下:
1 Student.java代码
3 测试代码
四 通过查找原因:是没有为Student的id设置GeneratedValue自动递增,删除数据库Student表,增加Student类的ID的GeneratedValue属性,hbm2ddl.auto先设置为create,创建表成功后在设置为auto或者update,这样就成功了
SSH+Oracle问题:org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
http://blog.csdn.net/wearegouest/archive/2010/07/04/5712385.aspx
Could not execute JDBC batch update
http://blog.163.com/leo_canton/blog/static/902931232008101610558474/
Err:Could not execute JDBC batch update
http://apps.hi.baidu.com/share/detail/19115426
一 环境:W7+Eclipse3.6+Mysql5+Hibernate3.6
二 报错如下:
17:52:03,252 WARN JDBCExceptionReporter:233 - SQL Error: 1062, SQLState: 23000
17:52:03,253 ERROR JDBCExceptionReporter:234 - Duplicate entry '1' for key 'PRIMARY'
17:52:03,255 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [org.hibernate.model.Student]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2436)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
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 org.hibernate.model.Test.main(Test.java:25)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2416)
... 11 more
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not insert: [org.hibernate.model.Student]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2436)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2856)
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 org.hibernate.model.Test.main(Test.java:25)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2416)
... 11 more
三 相关代码如下:
1 Student.java代码
@Entity public class Student { @Id private int id; // 。。。 }
3 测试代码
Student s = new Student(); //s.setId(1); s.setName("zhangsan2"); s.setAge(82); s.setSdate(new Date()); Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); session.save(s); session.getTransaction().commit(); HibernateUtil.getSessionFactory().close();
四 通过查找原因:是没有为Student的id设置GeneratedValue自动递增,删除数据库Student表,增加Student类的ID的GeneratedValue属性,hbm2ddl.auto先设置为create,创建表成功后在设置为auto或者update,这样就成功了
发表评论
-
Hibernate之自定义ID生成器
2011-09-15 10:40 6308一 xxx.hml.xml <id name=&q ... -
Hibernate之java.lang.UnsupportedOperationException: Can't write to a readonly obj
2011-09-15 08:56 3211参考资料 1 java.lang.UnsupportedOpe ... -
Hibernate:LazyInitializationException:could not initialize proxy - no Session
2011-05-11 14:33 11737一 参考资料 hibernate延迟加载的传说级错误 org. ... -
Hibernate:一对一双向主键关联
2011-04-05 11:53 4590参考资料: Hibernate系列:映射一对一主键双向关联 h ... -
Hibernate:setting property value with CGLIB (set hibernate.cglib.use_reflection_
2011-03-23 15:44 2103参考资料 1 Hibernate org.hibernate. ... -
Hibernate:一对一单向主键关联
2011-03-19 18:55 1493一 环境:W7+Eclipse3.6+JDK1.6+MySQL ... -
Hibernate:一对一双向外键关联
2011-03-18 20:44 1308一 环境:W7+Eclipse3.6+JDK1.6+MySQL ... -
Hibernate:一对一单向外键关联
2011-03-18 20:24 1402一 环境:W7+Eclipse3.6+JDK1.6+MySQL ... -
Hibernate:connection is not valid without active transaction
2011-03-18 13:44 3571参考资料 1 org.hibernate.HibernateE ... -
Hibernate搭建日志环境(log4j)及打印DDL语句
2011-03-13 16:26 3758一 参考资料 Log4j over SLF4J http:// ... -
Hibernate(3.6)之初识
2011-03-13 15:32 2809一 环境:W7+Eclipse3.6 二 所用Hibernat ... -
Hibernate: 主键生成策略(ID为varcahr2)
2011-02-23 16:11 13553一 环境: XP+Oracle10+Myeclipse6.6 ... -
S2SH整合:java.lang.IllegalArgumentException: node to traverse cannot be null
2011-02-23 10:38 7368参考资料 1 java.lang.IllegalArgumen ... -
Hibernate学习资料
2011-01-29 12:37 1646良葛格 Hibernate 3 入門和JPA 批注参考(中文) ... -
转载: get方法和load方法区别
2010-08-02 09:43 1328转载: get方法和load方法区别 http://wlh26 ...
相关推荐
7. **不能执行查询**:可能是由于SQL语句错误,如列名不存在,需检查SQL语法和表结构。 8. **invalid identity**:列名错误,检查数据库列名是否拼写错误或大小写不匹配。 9. **序列号冲突**:在数据库操作中,...
8. **不能执行查询**:这可能是由于数据库中的表或列名错误。检查SQL查询和数据库结构的一致性。 9. **无效的身份**:在数据库操作中,如果列名错误,会导致此问题。核对列名的拼写和大小写。 10. **表名或列名不...
Java错误大全涵盖了从基础异常到特定开源框架如Hibernate和Struts中可能出现的异常情况。以下是一些关键知识点的详细说明: 1. **错误类型:**Java中的错误通常分为两种主要类型,异常(Exception)和错误(Error)...
总结来说,文件中提及的错误涵盖了Java开发过程中可能遇到的多种问题,包括类加载错误、数据库操作异常、Hibernate框架相关错误、Struts框架错误以及Spring框架相关问题。针对这些问题,开发人员需要检查类路径设置...
17. **数据插入异常,GenericJDBCException: could not insert**:确保表已创建并且已提交插入操作。 18. **LazyInitializationException**或延迟加载异常:在查询中未启用fetch,导致延迟加载失败。考虑使用`fetch...
了解并掌握如何处理这些错误是每个Java开发者必备的技能之一。 #### 二、错误类型及解决方案 ##### 1. 数据查询不到 (NoDataFound) **问题描述**:当执行SQL查询语句时,如果数据库中不存在符合查询条件的数据,...
nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement ``` 这些错误信息表明MySQL在处理某些特殊字符(通常是中文字符)时出现了问题。 #### 原因分析 出现上述问题...
- **示例**:在`hibernate.cfg.xml`文件中引用了一个不存在的资源。 - **解决方法**: - 确认配置文件中引用的所有资源都存在且正确。 - 检查对象是否已经被初始化。 ##### 12. GenericJDBCException - **描述**...
3. **JDBC驱动更新**:错误日志中提到的`org.hibernate.exception.GenericJDBCException`表明可能是JDBC驱动的问题。检查你所使用的数据库(比如MySQL)的JDBC驱动是否为最新版本,如果不是,升级到最新版本通常可以...
17. **数据插入异常,GenericJDBCException: could not insert** - **可能的原因1**:表结构未正确建立。 - **可能的原因2**:未执行提交操作。 - **解决方法**:确保数据库表结构正确建立,并在事务结束后执行...
H2 1.4 "Lob not found" 问题 - 在 1.4.183 中修复!...org.hibernate.exception.GenericJDBCException: could not load an entity: [de.bwaldvogel.LobEntity#1] at org.hibernate.exception.SQLStateConverter.handl