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>

时间: 2024-10-27 12:06:23

org.hibernate.exception.ConstraintViolationException: could not insert:的相关文章

org.hibernate.exception.ConstraintViolationException

1.错误描述 Caused by:org.hibernate.exception.ConstraintViolationException:Could not execute JDBC batch update. 2.错误原因 3.解决办法

org hibernate exception ConstraintViolationException Could

1.错误描述 type Exception report message Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update description The server encountered an internal error that prevente

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

今天在使用hibernate搭建项目时碰到了这个错误,找了好半天没能发现错误的原因, 上网求助了一下 发现出现这个bug的原因是因为数据表使用了数据库的关键字(保留字) 然后检查了一下,发现字段名称都不是关键字,那问题出现在哪呢? 再次检查发现是数据表的名字使用了数据库的关键字order 很小的一个错误因为粗心浪费了很多时间, 原文地址:https://www.cnblogs.com/aihuadung/p/10202402.html

数据库问题ConstraintViolationException: could not insert

org.springframework.dao.DataIntegrityViolationException: could not insert: [com.integration.entity.User]; SQL [insert into USER1 (NAME, PASSWORD, TYPE) values (?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolat

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.hibernate.exception.GenericJDBCException: could not execute statement; Ecplise出现这个: 十二月 20, 2017 1:51:02 下午 org.apache.catalina.core.StandardWrapperVal

ERROR: Field &#39;PostId&#39; doesn&#39;t have a default value Exception in thread &quot;main&quot; org.hibernate.exception.GenericJDBCException: could not execute statement

例子: Post p = new Post(); p.setPostId(3); p.setPostName("技术"); 在执行数据保持时提示session.save(p); 的错误. INFO: HHH000232: Schema update complete Hibernate: insert into Post (postName) values (?) 八月 19, 2018 5:07:17 下午 org.hibernate.engine.jdbc.spi.SqlExcep

code is 9998;desc is 插入失败exception is org.hibernate.exception.JDBCConnectionException: Could not op

1.错误描述 [ERROR:]2015-05-05 09:27:12,090 [插入失败] org.hibernate.exception.JDBCConnectionException: Could not open connection at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132) at org.hibernate.exce

Caused by: code is 9998;desc is dao exception is org.hibernate.exception.DataException: error execu

1.错误描述 exception is org.hibernate.exception.DataException: error executing work at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingM

org.hibernate.exception.GenericJDBCException: Could not open connection

1.错误描述 org.hibernate.exception.GenericJDBCException: Could not open connection at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.conver