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 ...
随机推荐
- java parse 带英文单词的日期字符串 转 date (转化新浪微博api返回的时间)
拂晓风起 专注前端技术cocos2d.js.flash.html5,联系:kenkofox@qq.com.如果读者要找腾讯工作机会,请不吝推荐简历. 博客园 首页 新闻 新随笔 联系 管理 订阅 随笔 ...
- C++中public、protected、private的差别
第一: private,public,protected的訪问范围: private: 仅仅能由该类中的函数.其友元函数訪问,不能被不论什么其它訪问.该类的对象也不能訪问. protected: ...
- HOW TO: Synchronize changes when completing a P2V or V2V with VMware vCenter Converter Standalone 5.1
http://www.experts-exchange.com/Software/VMWare/A_11489-HOW-TO-Synchronize-changes-when-completing-a ...
- Go语言类型转换库【github.com/demdxx/gocast】的用法
一.导入库: go get github.com/demdxx/gocast 二.测试代码: // main.go package main import ( "fmt" &quo ...
- Go语言中Socket通信TCP服务端
1.用法: (1)定义远程IP地址.使用net.ResolveTCPAddr()方法,定义一个TCP地址,做为本机监听地址. (2)使用net.ListenTCP("tcp",lo ...
- 关于inode&硬连接
这两天看了一道面试题,什么是inode?我勒个去,第一次听说.于是Google了一下,发现下面这段内容讲解的非常不错,供大家参考. 一.inode是什么? 理解inode,要从文件储存说起.文件储存在 ...
- 转:初探nginx架构(一)
来源:http://tengine.taobao.org/book/chapter_02.html 众所周知,nginx性能高,而nginx的高性能与其架构是分不开的.那么nginx究竟是怎么样的呢? ...
- @Service注解的使用
首先,在applicationContext.xml文件中加一行: <context:component-scan base-package="com.hzhi.clas"/ ...
- VB 中 copymemory的有关问题
dim a() as long dim b() as bytecopymemory b(0),byval "1234",4 copymemory byval varptr(a(0) ...
- 用 bottle.py 写了个简单的升级包上传
可以当作一个 demo 来玩吧,在这里分享一下.里面涉及的内容包含了文件上传,cookie 设置和读取,重定向(redirect). from bottle import run, post, get ...