这是一个hibernate常见的问题。搜索出来最多的答案都是如下面这篇文章所述:

  http://blog.csdn.net/eyejava/article/details/1896492

  但我觉得我问题不在这里,因为在我添加一个新的实体类关系之前,所有的映射配置都没有问题的,但现在只要是这几个互相关联的实体类的操作均出现了问题。我的实体类关系如下:

  从图中可以发现,所有的实体类都和Dept直接或者间接有关系,这些实体类的操作都出现了问题。浏览器报的错是没有Dept这个实体类。

  

  由此回答启发,我去观察了数据库。果然发现问题是这样的:我的关系1多对一原本是不存在的,是我后来调整实体类关系的时候加上去的,数据库中有了deptId这一字段,但是这一字段值为null。删除了相关表中之前用于测试的数据之后果然一切都变得美好了。后来我去看日志文件,才发现日志文件中居然有这样的错误:

  2016-04-21 21:42:19,043 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Unsuccessful: alter table curriculum add index                    FKC5509C3B2405960D (deptId), add constraint FKC5509C3B2405960D foreign key (deptId) references twcs4sxau.dept (deptId)
  2016-04-21 21:42:19,044 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - Cannot add or update a child row: a foreign key constraint fails         (`twcs4sxau`.`#sql-a90_47`, CONSTRAINT `FKC5509C3B2405960D` FOREIGN KEY (`deptId`) REFERENCES `dept` (`deptId`))

  如果我早点看到这段话,会早点察觉到是数据库的问题的。

  从这次的错误中我总结出两点:

  1、出错了先看console,再看日志文件,得出错误原因。

  2、不要乱改实体类的关系。我是因为初次并且独立做这个项目,出了错只能自己后期发现,没有人商量或者提醒。毕设开始仓促,并没有好好设计就开始写代码了,这给我后期真是带来了无穷无尽的麻烦啊。

  另外我还看见一个回答很具有启发性:

  http://www.cnblogs.com/jianxh/articles/82350.html

  直接指出了是破坏了外键关系,让确定表的关系是否正确。这与我在日志文件中发现的提示相吻合。

No row with the given identifier exists:错误另解的更多相关文章

  1. Hibernate错误——No row with the given identifier exists

    错误 是用的是Hibernate自动建立的数据表,在进行数据库操作时,出现错误No row with the given identifier exists 解决 关系数据库一致性遭到了破坏,找到相关 ...

  2. Hibernate报错:org.hibernate.ObjectNotFoundException: No row with the given identifier exists 解决办法

    报错信息: org.hibernate.event.internal.DefaultLoadEventListener onLoad INFO: HHH000327: Error performing ...

  3. Hibernate常见问题 No row with the given identifier exists问题的解决办法及解决

    (1)在学习Hibernate的时候遇到了这个问题"No row with the given identifier exists"在网上一搜看到非常多人也遇到过这个问题! 问题的 ...

  4. org.hibernate.ObjectNotFoundException: No row with the given identifier exists

    维护老系统时出现的问题,出现的原因我简述一下: table1与table2是关联表,T1中有T2的主键 "T1_id",当T1中的 "T2_id" 不为null ...

  5. org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.zhuoshi.entity.Dep#1]

    报错信息: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.zhuoshi.e ...

  6. No row with the given identifier exists[ArtProject.Domains.Users#2]

      产生此问题的原因:              有两张表,table1和table2. 产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-on ...

  7. (转)收集:Hibernate中常见问题 No row with the given identifier exists问题的原因及解决

    Hibernate中No row with the given identifier exists问题的原因及解决 产生此问题的原因: 有两张表,table1和table2.产生此问题的原因就是tab ...

  8. org.hibernate.ObjectNotFoundException: No row with the given identifier exists解决办法

    hibernate-取消关联外键引用数据丢失抛异常的设置@NotFound hibernate项目里面配了很多many-to-one的关联,后台在查询数据时已经作了健全性判断,但还是经常抛出对象找不到 ...

  9. (转)No row with the given identifier exists问题的解决

    产生此问题的原因:         有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique ...

随机推荐

  1. 判断浏览器类型用 document.documentMode方式,

    if ( document.documentMode && document.documentMode < 9 ){ document.write( '<script sr ...

  2. Git和Github简单教程(转)

    这篇文章只挑一部分命令来讲,差不多够用就行的程度.如果需要其他命令,到时候再去其他地方了解就行了先在Github上写好再搬过来的:本文Github链接 目录: 零.Git是什么 一.Git的主要功能: ...

  3. PCB上过孔via钻孔的直径如何设置 是任意的吗 谈谈PCB钻孔工艺及规格

    PCB上过孔via钻孔的直径如何设置,是不是可以随便填入一个直径尺寸就行了?比如我的走线宽度是6mil,那我的via过孔直径也设置为6mil,节约布线空间岂不是更好?这样的设计板厂是否都能按照设计规格 ...

  4. Spark1.6.2 java实现读取json数据文件插入MySql数据库

    public class Main implements Serializable { /** * */ private static final long serialVersionUID = -8 ...

  5. chrome中hack解决input:-webkit-autofill自定义样式

    在使用chrome浏览器设计网页时,想将input背景改成透明,也就是 background-color:transparent; 可是效果并不如人意 hack方法: input:-webkit-au ...

  6. "undefined method `root' for nil:NilClass" error when using "pod install" 解决办法

    如果pod undate 的时候报错"undefined method `root' for nil:NilClass" error when using "pod in ...

  7. 转摘 MySQL扫盲篇

    一下文章摘自:http://www.jellythink.com/archives/636 MySQL扫盲篇 2014-09-15 分类:MySQL / 数据库 阅读(1412) 评论(1)  为什么 ...

  8. php面试题

    1.用PHP打印出前一天的时间格式是2006-5-10 22:21:21(2分) <?php date_default_timezone_set('Asia/shanghai'); echo d ...

  9. LeetCode Find All Anagrams in a String

    原题链接在这里:https://leetcode.com/problems/find-all-anagrams-in-a-string/ 题目: Given a string s and a non- ...

  10. C++学习笔记 四种新式类型转换

    static_cast ,dynamic_cast,const_cast,reinterpret_cast static_cast 定义:通俗的说就是静态显式转换,用于基本的数据类型转换,及指针之间的 ...