org.hibernate.exception.ConstraintViolationException: could not insert:
org.hibernate.exception.ConstraintViolationException: could not insert:
报错原由于xxx.hbm.xml文件里的主键类型设置有问题;
当我们的数据库表没实用自增长的int型id。而用的varchar就可能报上面的错误,
假设,主键的生成类型设置为identity或者native的时候底层数据库会自己主动生成一个long,short或者是int,假设ID设计的是用String,数据库就无法插入的,所以假设你的数据库的ID设计的是用String型的,最好是用assigned.
比如:
<id name="userId" type="java.lang.String">
<column name="UserId" length="32" />
<generator class="assigned" />
</id>
org.hibernate.exception.ConstraintViolationException: could not insert:的更多相关文章
- Hibernate: org.hibernate.exception.SQLGrammarException: could not insert: 错误
最近在学习Java Web,今天刚接触Hibernate.学习的书籍是<轻量级Java EE企业应用实战(第3版)>.书中367页5.2.2中给予的Hibernate例子中的代码运行有以下 ...
- org.hibernate.exception.ConstraintViolationException
1.错误描述 Caused by:org.hibernate.exception.ConstraintViolationException:Could not execute JDBC batch u ...
- 在使用Hibernate save()方法的时候 报错: org.hibernate.exception.ConstraintViolationException:could not perform addBath
org.hibernate.exception.ConstraintViolationException:could not perform addBath 错误可能原因:实体属性的值与数据库字段类型 ...
- org.hibernate.exception.ConstraintViolationException: could not delete:
转自:http://fireinwind.iteye.com/blog/848515 异常描述: org.hibernate.exception.ConstraintViolationExceptio ...
- SpringBoot保存数据报错:could not execute statement; SQL [n/a]; constraint [PRIMARY];nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
使用SpringBoot做JAVA开发时,用Repository.save();保存数据的时候遇到了报错: could not execute statement; SQL [n/a]; constr ...
- 解决org.hibernate.exception.SQLGrammarException:could not insert
今天在使用hibernate搭建项目时碰到了这个错误,找了好半天没能发现错误的原因, 上网求助了一下 发现出现这个bug的原因是因为数据表使用了数据库的关键字(保留字) 然后检查了一下,发现字段名称都 ...
- 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException
今天遇到了一个很坑人的问题,从昨晚一直搞到今天早上,终于发现了,先整理下: [背景]:利用hibernate自动给mysql创建一个表,然后为表里面添加一行记录,非常的简单(当然其中还涉及到sprin ...
- 严重: Could not synchronize database state with session org.hibernate.exception.DataException: Could not execute JDBC batch update
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Monaco; color: #ff2600 } p.p2 { margin: 0.0px 0 ...
- 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 ...
随机推荐
- mybatis学习资源
官网:http://mybatis.org/index.html 代码:https://code.google.com/p/mybatisnet/ wiki:http://zh.wikipedia.o ...
- linux下安装与删除软件
linux下安装与删除软件 (2005-07-04 11:24:10) 转载▼ 标签: 杂谈 分类: MSN搬家 现在linuxx下的软件大都是rpm,deb.tar.gz和tar.bz2格式.1.r ...
- struts-config.xml配置详解
<struts-config>是struts的根元素,它主要有8个子元素,DTD定义如下: <!ELEMENT struts-config (data-sources?,form-b ...
- C#.NET常见问题(FAQ)-如何把文本复制粘贴到文本框的光标位置
前面已经通过Clipborad.SetText之后,这里就要先把目标文本框的文本改成插入之后的值,然后修改光标所在位置
- 配置windows失败,不能进入系统
曾经,遇到过<配置windows失败,还原更新,请勿关机>,可多次尝试都无效. 包括: 1. 安全模式(进不了系统) 2. 带命令的安全模式 3. 最后一次正确的配置 4 ...
- ZH奶酪:使用PHP调用REST API
原文:http://yuguo.us/weblog/php-rest-api/ 表征状态转移(英文:REpresentational State Transfer,简称REST)是Roy Fieldi ...
- Word2007的自动插入题注!
要在word中插入图片,是截屏获取的图片,还未保存成位图.要使用word2007的自动插入题注时,发现选项里面没有关于word图片的选项,2003里面有个word图片(差不多是这个叫法吧),在2003 ...
- Statement、PreparedStatemnt、CallableStatement
第一.Statement(Statement代表一个特定的容器,来对一个特定的数据库执行语句) * 执行查询的方法 Statement=Connection.createStatement();//创 ...
- Java千百问_05面向对象(005)_接口和抽象类有什么差别
点击进入_很多其它_Java千百问 1.接口和抽象类有什么差别 在Java语言中.抽象类abstract class和接口interface是抽象定义的两种机制. 正是因为这两种机制的存在,才赋予了J ...
- mysql计算时间差值,单位分钟数
TIMESTAMPDIFF(MINUTE, 开始时间, 结束时间) as 时间差(单位:分钟数) TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr ...