现在的位置: 首页 > 综合 > 正文

No row with the given identifier exists

2013年10月19日 ⁄ 综合 ⁄ 共 1392字 ⁄ 字号 评论关闭

出现异常org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException: No row with the given identifier exists

 

一.

No row with the given identifier exists 解决方法

有两张表,a和b.产生此问题的原因就是a里做了关联<one-
to-one>或者<many-to-one
unique="true">(特殊的多对一映射,实际就是一对一)来关联b.当hibernate查找的时候,b里的数据没有与a相匹配的,这样
就会报No row with the given identifier exists这个错.(一句话,就是数据的问题!)

      假如说,a里有自身的主键id1,还有b的主键id2,这两个字段.

      如果hibenrate设置的单项关联,即使a中的id2为null值,b中id2中有值,查询都不会出错.但是如果a中的id2字段有值,但是这个值在b中主键值里并没有,就会报上面的错!

      如果hibernate是双向关联,那么a中的id2为null值,但是b中如果有值,就会报这个错.这种情况目前的解决办法就是改成单项关联,或者把不对应的数据改对!

二.
hibernate的一些常见的错误

No row with the given identifier exists

表示你现在查询的对象所关联的对象有问题,一般是因为数据的问题(该对象所关联的对象找不到)

Caused by: org.dom4j.DocumentException: Invalid byte 2 of 2-byte
UTF-8 sequence. Nested exception: Invalid byte 2 of 2-byte UTF-8
sequence.
如果出现这行错误说明你的xml配置文件有不规范的字符,检查下。

net.sf.hibernate.MappingException: Error reading resource: hibernate/Hello_Bean.hbm.xml

如果出现这行错误说明你的hibernate的XML配置文件有错

net.sf.hibernate.MappingException: Resource: hibernate/Hello_Bean.hbm.xml not found

如果出现这行错误说明hibernate的XML配置文件没有找到,你应该把XML文件放在与你的类文件同个目录下,本文中是放在hibernateclasseshibernate目录下,也就是跟Hello_Bean.class类文件一起。

net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property name in class hibernate.Hello_Bean

如果出现这行错误说明你的xml文件里设置的字段名name的值与Hello_Bean.java类里的getXXX或setXXX方法不一致。

net.sf.hibernate.HibernateException: JDBC Driver class not found: org.gjt.mm.mysql.Driver

如果出现这行错误说明你的MYSQL驱动没有加进JB库里或者不在CLASSPATH里。

抱歉!评论已关闭.