关于Hibernate:No row with the given identifier exists报错的解决办法

来源:互联网 发布:广联达相关软件 编辑:程序博客网 时间:2024/05/21 14:59

我们在用many-to-one配置关联的时候,有时关联查询会报No row with the given identifier exists的错误,究其原因是数据不完整(关联的对象值为null),产生脏数据。对此解决这个报错信息的方法一般有两个:
一、改数据
找到脏数据源头,删除或更改,不过个人不怎么建议使用这个方法。

二、在many-to-one配置的时候将策略为忽略。
由于在配置many-to-one的时候,没有配置not-found属性,该属性值就默认为Exception,也就是抛出异常,我们只将这个属性值改为ignore即可(忽略)。例如

    <many-to-one               name="conPo"              class="com.keda.project.peijian.inproc.po.KedaPjInprocConsmatmain"              fetch="select"              lazy="false"              not-null="false"              **not-found="ignore"**              column="conid"              insert="false"               update="false"           />
0 0
原创粉丝点击