关于GenericJDBCException的问题
在spring和hibernate整合的初步阶段,还没有编辑hibernate.cfg.xml这个文件,只有一个beans.xml文件。此时遇到了一个bug。
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [com.test.model.User]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2176)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2656)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:563)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:551)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
at com.test.dao.impl.UserDAOImpl.save(UserDAOImpl.java:33)
at com.test.service.UserService.add(UserService.java:30)
at com.test.action.UserAction.main(UserAction.java:23)
Caused by: java.sql.SQLException: Field 'id' 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.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
... 18 more
主要看第一行,是一个GenericJDBCException类型错误,把错误在网上找了一下,大多数回答都是基于有了hibernate.cfg.xml这个文件的情况下回答的,如:
原因:当使用bookid当主键的时候 使用hibernate 并且将其实体映射 <generator class="native" /> 设为自动增长时会报此异常,因为uuid为字符型的无法使用数字型的自动增长。
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id; @Entity
public class User {
private int id;
private String name; @Id
@GeneratedValue
public int getid() {
return id;
}
public void setid(int id) {
this.id = id;
}
public String getname() {
return name;
}
public void setname(String name) {
this.name = name;
} }
只需要把@GeneratedValue去掉就行了。
关于GenericJDBCException的问题的更多相关文章
- 登录Cloudera Manager时报错org.hibernate.exception.GenericJDBCException: Could not open connection
去Cloudera Server上边看了一下日志: cat /opt/cloudera-manager/log/cloudera-scm-server/cloudera-scm-server.log ...
- hibernate异常:org.hibernate.exception.GenericJDBCException
异常:org.hibernate.exception.GenericJDBCException 提示:Cannot open connection 提示:不能打开链接 一般这个异常是由 java.sq ...
- 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.h ...
- org.hibernate.exception.GenericJDBCException: Could not open connection
1.错误描述 org.hibernate.exception.GenericJDBCException: Could not open connection at org.hibernate.exce ...
- Hibernate学习错误集锦-GenericJDBCException: could not execute statement
初次使用Hibernate,进行junit测试,报如下错误. 原因:Hibernate帮我们管理主键了,我们不需要对主键赋值,并且主键是自增的.所以在数据库中,逐渐选项应当勾选 org.hiberna ...
- cloudera-scm-server启动时出现Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection问题解决方法(图文详解)
问题现象 查看 [root@cmbigdata1 cloudera-scm-server]# pwd /var/log/cloudera-scm-server [root@cmbigdata1 clo ...
- 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); 的 ...
- hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)
首先hibernate级联删除的前提是,首先需要在映射文件中配置,配置多表之间的关联关系: 下面以部门表(Dept)和员工表(Emp)为例: 1.在Emp.hbm.xml映射文件中配置many-to- ...
- javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: ResultSet is from UPDATE. No Data.
Java jpa调用存储过程,抛出异常如下: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCEx ...
随机推荐
- Maven DebugConfiguration配置运行内存
-Xms256M -Xmx512M -XX:PermSize=256m -XX:MaxPermSize=512m
- spark sql cache时发现的空字符串问题
博客园首发,转帖请注明地址:https://www.cnblogs.com/tzxxh/p/10267202.html 图一 图1未做cache,直接过滤expression列的 null 和空字符串 ...
- python学习——初始面向对象
一.讲在前面 编程的世界中有三大体系,面向过程.面向函数和面向对象编程.而面向过程的编程就包括了面向函数编程,接下来说一下面向对象.假如 ,你现在是一家游戏公司的开发人员,现在需要你开发一款叫做< ...
- CodingLabs - MySQL索引背后的数据结构及算法原理
原文:CodingLabs - MySQL索引背后的数据结构及算法原理 首页 | 标签 | 关于我 | +订阅 | 微博 MySQL索引背后的数据结构及算法原理 作者 张洋 | 发布于 2011-10 ...
- Ubuntu 安装 搜狗输入法
1.去下载搜狗输入法安装包: https://pinyin.sogou.com/linux/ 2.安装 sudo dpkg sougou****.deb 3.去设置 参考:https://blog.c ...
- java操作HDFS
package com.lei.hadoop; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Fil ...
- 创龙DSP6748开发板上电测试-第一篇
1. 创龙DSP6748开发板测试.2980元的售价很高,我估计新的1200元比较合适,当然创龙定价是按照供需关系的.仿真器XDS100V2卖598元,真是狮子大张口. 2. 上电是5V-2A的电源. ...
- 数据库c3p0配置文件
<?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-con ...
- 「日常训练」Battle Over Cities - Hard Version(PAT-TOP-1001)
题意与分析 题意真的很简单,实在不想讲了,简单说下做法吧. 枚举删除每个点,然后求最小生成树,如果这个路已经存在那么边权就是0,否则按照原来的处理,之后求花费,然后判整个图是否联通(并查集有几个roo ...
- Selenium 入门到精通系列:五
Selenium 入门到精通系列 PS:显式等待.隐式等待.强制等待方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019 ...