Hibernate学习错误集锦-GenericJDBCException: could not execute statement

初次使用Hibernate,进行junit测试,报如下错误。

原因:Hibernate帮我们管理主键了,我们不需要对主键赋值,并且主键是自增的。所以在数据库中,逐渐选项应当勾选

org.hibernate.exception.GenericJDBCException: could not execute statement

at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)

at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)

at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)

at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)

at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2792)

at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3363)

at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)

at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:597)

at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:232)

at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:213)

at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:256)

at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:317)

at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:272)

at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:178)

at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:109)

at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)

at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)

at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)

at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)

at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)

at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:679)

at org.hibernate.internal.SessionImpl.save(SessionImpl.java:671)

at org.hibernate.internal.SessionImpl.save(SessionImpl.java:666)

at test.Demo1.function(Demo1.java:42)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)

at org.junit.runners.ParentRunner.run(ParentRunner.java:292)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Caused by: java.sql.SQLException: Field ‘CustomerId‘ doesn‘t have a default value

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)

at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2046)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1964)

at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1949)

at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)

... 45 more

时间: 2024-10-25 06:57:05

Hibernate学习错误集锦-GenericJDBCException: could not execute statement的相关文章

ERROR: Field 'PostId' doesn't have a default value Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement

例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的错误. INFO: HHH000232: Schema update complete Hibernate: insert into Post (postName) values (?) 八月 19, 2018 5:07:17 下午 org.hibernate.engine.jdbc.spi.SqlExcep

Hibernate插入错误:GenericJDBCException: could not insert:

参考: http://blog.csdn.net/woshishui6501/article/details/7563070#reply http://bbs.csdn.net/topics/240046731 http://blog.chinaunix.net/uid-20556037-id-2810929.html 数据库中一般不能建立user(表名为User)表,将User类改名,重新建立映射,问题就可以解决 当然,还有另一种情况,就是类中id类型错误,要设置为Integer型才可以设置自

HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement

1.什么操作出现:当我在项目中添加产品或者修改时,浏览器出现HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement; Ecplise出现这个: 十二月 20, 2017 1:51:02 下午 org.apache.catalina.core.StandardWrapperVal

GenericJDBCException: could not execute statement 错误解决

"message":"could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement","status":"500" 1.数据库表主键未设置自增 2.数据库表类型与代码中的数据类型不相同 原文地址:https://www.cnblogs.com/4

hibernate框架学习错误集锦-org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL)

最近学习ssh框架,总是出现这问题,后查证是没有开启事务. 如果采用注解方式,直接在业务层加@Transactional 并引入import org.springframework.transaction.annotation.Transactional; 详细信息,可以参考下面博客: 参考资料:http://blog.csdn.net/longxia1987/article/details/7819242 org.springframework.dao.InvalidDataAccessApi

Spring.Net框架学习错误集锦1

最近IoC框架非常火热,所以就学习了非常流行的IOC框架之一spring.NET,遇到如下问题: Error creating context 'spring.root': Could not load type from string value 'Spring.net.EFUserInfoDal, Spring.Net'. 仔细查看发现在配置文件中配置Spring.Net的子节点的时候配置错误,应该是配置为该项目的命名空间不是Spring.Net这个,这里我的命名空间是Spring.NetD

学习hibernate出现错误--之二(方言)

最近在学习hibernate,其中关于错误的问题真是一头大,各种各样的奇葩错误层出不穷,简直是受不了了. 用hibernate操作数据库,在使用hibernate进行把持久化类自动生成相关数据库表的时候,出现了一些问题. 其中有上篇错误<hibernate学习错误--之一>,在上篇错误解决完成后,进行测试时通过了,没有报错,但是却没有生成表,控制台窗口显示一些找不到相关table的警告,找了半天也不知道错误出现再哪儿,查看配置文件感觉也没问题,配置文件上的一些基本信息,有些是原封不动的从以前一

hibernate 异常:could not execute statement

错误信息: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [72000]; error code [12899]; could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement 今天出现这个问题的原因是我

HTTP Status 500 - JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [HY000]; error code [1364]; could not execute statement; nested exception is org.hibernate.exception.Ge

HTTP Status 500 - JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [HY000]; error code [1364]; could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement 翻译