分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

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

发布时间:2023-09-06 01:49责任编辑:苏小强关键词:暂无标签
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

原文地址:https://www.cnblogs.com/cn-chy-com/p/8810374.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved