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:的更多相关文章

  1. Hibernate: org.hibernate.exception.SQLGrammarException: could not insert: 错误

    最近在学习Java Web,今天刚接触Hibernate.学习的书籍是<轻量级Java EE企业应用实战(第3版)>.书中367页5.2.2中给予的Hibernate例子中的代码运行有以下 ...

  2. org.hibernate.exception.ConstraintViolationException

    1.错误描述 Caused by:org.hibernate.exception.ConstraintViolationException:Could not execute JDBC batch u ...

  3. 在使用Hibernate save()方法的时候 报错: org.hibernate.exception.ConstraintViolationException:could not perform addBath

    org.hibernate.exception.ConstraintViolationException:could not perform addBath 错误可能原因:实体属性的值与数据库字段类型 ...

  4. org.hibernate.exception.ConstraintViolationException: could not delete:

    转自:http://fireinwind.iteye.com/blog/848515 异常描述: org.hibernate.exception.ConstraintViolationExceptio ...

  5. 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 ...

  6. 解决org.hibernate.exception.SQLGrammarException:could not insert

    今天在使用hibernate搭建项目时碰到了这个错误,找了好半天没能发现错误的原因, 上网求助了一下 发现出现这个bug的原因是因为数据表使用了数据库的关键字(保留字) 然后检查了一下,发现字段名称都 ...

  7. 用hibernate自动创建mysql表,添加失败org.hibernate.exception.SQLGrammarException

    今天遇到了一个很坑人的问题,从昨晚一直搞到今天早上,终于发现了,先整理下: [背景]:利用hibernate自动给mysql创建一个表,然后为表里面添加一行记录,非常的简单(当然其中还涉及到sprin ...

  8. 严重: 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 ...

  9. 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 ...

随机推荐

  1. mysql 分区说明

    当 MySQL的总记录数超过了100万后,性能会大幅下降,可以采用分区方案 分区允许根据指定的规则,跨文件系统分配单个表的多个部分.表的不同部分在不同的位置被存储为单独的表. 1.先看下innodb的 ...

  2. iOS 生成pem证书

    openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes     需要通过终端命令将这些文件转换为PEM格式:openssl p ...

  3. Unity3D 学习 创建简单的按钮、相应事件

    选择file -->new project 然后保存到相应的地方 下面是这个刚创建的工程效果图. 然后创建一个C# Script ||定位到最左下角找到  assets --> creat ...

  4. iOS开发技巧 - 使用UIDatePicker来选择日期和时间

    (Swift) import UIKit class ViewController: UIViewController { var datePicker: UIDatePicker! func dat ...

  5. js开发思路

    $.ui = $.ui || {}; var version = $.ui.version = "1.12.1"; // 是否为ie浏览器 var ie = $.ui.ie = ! ...

  6. JQuery为textarea添加maxlength

    <html> <head> <title>JQuery为textarea添加maxlength</title> <script type=&quo ...

  7. LintCode: Longest Words

    C++ class Solution { public: /** * @param dictionary: a vector of strings * @return: a vector of str ...

  8. HTML页面跳转的5种方式

    下面列了五个例子来详细说明,这几个例子的主要功能是:在5秒后,自动跳转到同目录下的hello.html(根据自己需要自行修改)文件. 1) html的实现 <head> <!-- 以 ...

  9. Linux中找出占用内存最多的前N个进程

    一.使用ps命令 ps -aux | sort -k4nr | head -N *命令详解: 1. head:-N可以指定显示的行数,默认显示10行. 2. ps:参数a指代all——所有的进程,u指 ...

  10. hadoop mahout 算法和API说明

    org.apache.mahout.cf.taste.hadoop.item.RecommenderJob.main(args) --input 偏好数据路径,文本文件.格式 userid\t ite ...