org.hibernate.exception.ConstraintViolationException: could not insert
来源:互联网 发布:程序员必备生活用品 编辑:程序博客网 时间:2024/05/29 18:28
org.hibernate.exception.ConstraintViolationException: could not insert
报错原因: 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.
- 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:
- Java编程问题——@SuppressWarnings("deprecation")
- hdu 1701 ACMer(水)
- Android ClickableSpan 应用实例
- 一道超级坑爹的题
- strut2(xwork)中的类型转换策略
- org.hibernate.exception.ConstraintViolationException: could not insert
- webservice(一)---c#开发webservice
- java中的值传递和引用传递
- ExtJS Ajax简单用法
- 线程基础之产生线程
- WCF 宿主里面显示客户端信息
- IE,FF客户端浏览器缓存机制and服务器设置的expires, Cache-Control,no-cache,no-store机制
- 理解OpenGL拾取模式(OpenGL Picking)
- Android 嵌入式数据库SQLite练习小记录