org.hibernate.exception.ConstraintViolationException: could not execute statment 异常解决
来源:互联网 发布:lol国服数据 编辑:程序博客网 时间:2024/06/06 12:24
这个异常是因为违反了约束而造成的。
应首先检查主键问题:
传入的主键绑定的值是否在数据库中还存在。
例如:
学生和班级
班级表的id只有 2和3,id为1的班级由于某些原因被删除了。
新添加的学生表有同学的班级id指向了1,那么就造成了这种异常。
由于是hibernate完成,
有两种方式来处理这种异常:
1.在学生表设置级联,添加学生时,如果班级不存在则自动创建(不推荐,因为没有意义)
2.检查插入时学生指向的班级id,如果在班级表不存在则抛出自定义异常(推荐)
还请补充能出现这个异常的情况
0 0
- org.hibernate.exception.ConstraintViolationException: could not execute statment 异常解决
- 解决:org.hibernate.exception.ConstraintViolationException: could not execute statement
- 解决异常org.hibernate.exception.ConstraintViolationException: could not delete
- 解决异常org.hibernate.exception.ConstraintViolationException: could not delete:
- 解决异常org.hibernate.exception.ConstraintViolationException: could not delete:
- Hibernate org.hibernate.exception.ConstraintViolationException: could not execute update query 异常分析
- 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 execute JDBC batch update
- 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 JDBC batch update解决
- 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:
- UVa 11134 Fabled Rooks
- 素数环
- grep 命令
- A tutorial on Principal Components Analysis - 主成分分析(PCA)教程
- 集合概述
- org.hibernate.exception.ConstraintViolationException: could not execute statment 异常解决
- 9
- Linux 文件类型与扩展名
- 根据第xx天推算日期
- Java 基础
- JavaScript中的数字
- Abp之工作单元与事务
- 【英语学习】2017年1月英语总结
- 数十种TensorFlow实现案例汇集:代码+笔记