hibernate-取消关联外键引用数据丢失抛异常的设置@NotFound

hibernate项目里面配了很多many-to-one的关联,后台在查询数据时已经作了健全性判断,但还是经常抛出对象找不到异常:

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

因为系统给用户使用过程中库表的数据会常发生变化,最常见的是人员变化,原先引用的User 在库表没了,hibernate 多对一关联,多的这端引用的一的那端,如此引用值在一的那端找不到数据,默认就会抛出异常;而后台判断控制不了此问题。解决办法:
在many-to-one的这端加上属性:not-found=ignore
hibernate many-to-one的属性not-found,用来指定引用的外键不存在时如何处理:

exception(默认)抛出异常
ignore 忽略

注解

@NotFound(action=NotFoundAction.IGNORE) 
实列

@ManyToOne(cascade={CascadeType.PERSIST},targetEntity=QeTopic.class)
@JoinColumn(name="topic_id",updatable=false)
@NotFound(action=NotFoundAction.IGNORE)
private QeTopic qeTopic;
配置文件

在<many-to-one>中设置not-found="ignore"
也可以将垃圾数据从数据库删掉

 

org.hibernate.ObjectNotFoundException: No row with the given identifier exists解决办法的更多相关文章

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

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

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

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

  3. 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 ...

  4. org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [cn.facekee.cms.entity.CmsFansgroup#195]

    刚开始报错还是报的稀奇古怪的错误,让我纠结了好久,再三检查报错的位置,发现并没有错误,最后认真分析查看每行报错的信息才找到如题所述的错误!!!!! 报这种错误的原因可能是POJO映射文件中的字段和数据 ...

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

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

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

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

  7. 关于Hibernate中No row with the given identifier exists问题的原因及解决

    今天遇到一个bug,截图如下 有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique=&q ...

  8. Hibernate3.x异常No row with the given identifier exists 解决方法

    这个异常是在 多对一关系映射时,一方表中对应的数据不存在才抛出的.原来的配置: <many-to-one class="com.art.model.user.UserInfo" ...

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

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

随机推荐

  1. java反射(java.lang.reflect)---java.lang.reflect.Modifier中状态码

    1. 详情请看jvm(虚拟机)规范 java.lang.reflect.Modifier public static final int ABSTRACT 1024 public static fin ...

  2. wxPython的简单应用

  3. LeetCode算法题-Maximum Depth of N-ary Tree(Java实现)

    这是悦乐书的第261次更新,第274篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第128题(顺位题号是559).给定n-ary树,找到它的最大深度.最大深度是从根节点到 ...

  4. Docker: 企业级镜像仓库Harbor部署(http)

    Harbor离线安装包下载地址:https://github.com/goharbor/harbor Docker compose(安装harbor需要用到docker compose)下载地址:ht ...

  5. centos7下 svn的配置

    安装svn yum install subversion 查看安装版本 svnserve --version 创建svn版本库目录 mkdir -p /root/svn/test 创建svn版本库 s ...

  6. CSS---文档流布局 | 脱标-postion-zindex | 脱标-浮动

    一.css文档流布局概念 1.1,什么是标准文档流 1.2,标准文档流下有哪些微观现象 二.CSS---position属性 2.1,position:relative 2.2,position:fi ...

  7. 日志学习系列(一)——Log4net的基础知识学习

    今天把Log4net日志记录做了封装,作为一个公共的类库.记录一下应该注意的地方.先了解一下log4net的理论知识. 参考百度百科 一.log4net是什么? log4net库是Apache log ...

  8. koa 路由配置

    Koa 路由 路由(Routing)是由一个 URI(或者叫路径)和一个特定的 HTTP 方法(GET.POST 等) 组成的,涉及到应用如何响应客户端对某个网站节点的访问. 通俗的讲:路由就是根据不 ...

  9. Python + Tornado 搭建自动回复微信公众号

    1 通过 pip 安装 wechat-python-sdk , Requests 以及 Tornado pip install tornado pip install wechat-sdk pip i ...

  10. js中“==”与“===”区别

    直接上代码 if(2==='2'){ console.log(true) }else{ console.log(false) } //打印结果 false if(2=='2'){ console.lo ...