org.hibernate.exception.ConstraintViolationException: could not insert
来源:互联网 发布:网络推广付费平台 编辑:程序博客网 时间:2024/05/17 04:15
出现这个问题并不是因为mysql数据库本身的什么问题,最主要的问题是在指定表间关系的时候出现了错误。拿我这个问题来说吧,我做的是多对一的双向映射,再做单向的时候同样的代码,只是没有映射关系,可是一样很正确,使用注解做结果也是对的,可是使用文件配置双向一对多的时候就出现了上面的问题,
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.edu.model"> <class name="User" table="user"> <id name="id" column="uid"> <generator class="native"></generator> </id> <property name="uname" column="name" length="64"/> <many-to-one name="group" column="ggroup" cascade="all"></many-to-one> </class> </hibernate-mapping>
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.edu.model"> <class name="Group" table="mygroup"> <id name="id" column="gid"> <generator class="native"></generator> </id> <property name="gname" column="name" length="64" /> <set name="users" > <key column="ggroup"></key> <one-to-many class="cn.edu.model.User"/> </set></class> </hibernate-mapping>
错误就出在一的这一方,在set中,有一个<key column="ggroup"></key>其中的这个column必须与多的那一端配置时指定的column相同,否则就错了。
- 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:
- Android基本组件02(TextView)
- 这些年做项目带新人的经验总结
- 嵌入式系统开发人员的知识结构
- Android特色开发之桌面组件
- 搜索
- org.hibernate.exception.ConstraintViolationException: could not insert
- linux gdb 调试多线程 单独调试线程
- 网络基础
- 设置电脑屏幕保护色
- 第一章:概述
- java 开发服务器
- 第二章:OSI模型和TCPIP协议族
- 第三章:底层技术
- 反面模式(Anti-pattern)