org.hibernate.exception.ConstraintViolationException: could not insert
来源:互联网 发布:乐高幻影忍者玩具淘宝 编辑:程序博客网 时间:2024/06/06 07:54
报错原因: generator id设置问题
hibernate的映射文件bean.hbm.xml是跟库表一一对应的,如果库表中存在主键,需要自动生成就用native,有时需要在我们insert时就给他赋值,用assigned。
example:
如果是要让他自动生成的话用如下:
<id name="id" type="java.lang.Integer">
<column name="ID" />
<generator class="native"></generator>
</id>
insert时需要为主键赋值如下:
<id name="id" type="java.lang.String">
<column name="ID" />
<generator class="assigned"></generator>
</id>
因为采用了native的方法,底层数据库会自动生成一个long,short或者是int,如果ID设计的是用String,所以数据库无法插入的,所以如果你的数据库的ID设计的是用String型的,最好是用assinged.
0 0
- org.hibernate.exception.ConstraintViolationException: could not insert
- org.hibernate.exception.ConstraintViolationException: could not insert
- org.hibernate.exception.ConstraintViolationException: could not insert
- org.hibernate.exception.ConstraintViolationException: could not insert:
- org.hibernate.exception.ConstraintViolationException: could not insert解决
- 手工插入时候出现org.hibernate.exception.ConstraintViolationException: could not insert
- 解决异常org.hibernate.exception.ConstraintViolationException: could not delete
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- 解决异常org.hibernate.exception.ConstraintViolationException: could not delete:
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- 解决异常org.hibernate.exception.ConstraintViolationException: could not delete:
- org.hibernate.exception.ConstraintViolationException: could not execute statment 异常解决
- org.hibernate.exception.ConstraintViolationException: could not execute statement
- org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
- 解决:org.hibernate.exception.ConstraintViolationException: could not execute statement
- org.hibernate.exception.GenericJDBCException: could not insert:
- HDU 2814 Interesting Fibonacci 循环节
- CentOs使用yum方式安装wine 并安装Source Insight
- poj3211 Washing Clothes
- 胜利大逃亡
- 自定义ClassLoader
- org.hibernate.exception.ConstraintViolationException: could not insert
- windows驱动数字签名
- 解决mysql自动断掉连接的问题
- 关系型数据库与NOSQL
- 钛备份 - Titanium Backup Pro v6.2.0-Test4 直装破解版
- POJ 2632 Crashing Robots
- [Leetcode] Binary Tree Zigzag Level Order Traversal
- CNN相关资料
- POJ 2082