Hibernate异常:No row with the given identifier exists
来源:互联网 发布:数据库采集 编辑:程序博客网 时间:2024/06/06 05:31
Hibernate中常见问题 No row with the given identifier exists问题的原因及解决
上面引用的这篇文章,解释的挺好的,可以参考。
还有一种关于这个Hibernate异常的解决方法:
就是在Hibernate框架下,各个类都存在着互相引用的关系,websiteInfo 网站表 和 UserInfo 用户表,w 表 依赖 u表。
比如:张三 创建了 一个网站数据。
website实体:
@Entity@Table(name = "TBL_WEBSITE_INFO", schema = "SSP")public class WebsiteInfo implements java.io.Serializable {// Fieldsprivate static final long serialVersionUID = -5020142908658683873L;private long id;private String websiteName;private String websiteUrl;private UserInfo userId;// Constructors/** * default constructor */public WebsiteInfo() {}..getter () 和 setter () ....<pre name="code" class="java">.<span style="white-space:pre"></span>
<span style="white-space:pre"></span>@Id<span></span>@SequenceGenerator(name = "seqWEBSITE", sequenceName = "SSP_WEBSITE")<span></span>@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqWEBSITE")<span></span>@Column(name = "ID", unique = true, nullable = false, precision = 10, scale = 0)<span></span>public long getId() {<span></span>return this.id;<span></span>}<span></span>public void setId(long id) {<span></span>this.id = id;<span></span>}
<span style="white-space:pre"></span>@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = true)<span style="white-space:pre"></span>@JoinColumn(name = "USER_ID")<span style="white-space:pre"></span>public UserInfo getUserId() {<span style="white-space:pre"></span>return this.userId;<span style="white-space:pre"></span>}<span style="white-space:pre"></span>public void setUserId(UserInfo userId) {<span style="white-space:pre"></span>this.userId = userId;<span style="white-space:pre"></span>}
<span style="white-space:pre"></span>。。。。
比如 jack 创建了一条website的数据,当你在查询网站数据的时候,hibernate就会根据映射关系,也会加载userinfo的表,去找 jack 这条数据,如果找不到,那么就会抛异常
org.springframework.orm.hibernate4.HibernateObjectRetrievalFailureException: No row with the given identifier exists:
对应这个异常,
可以这样的处理逻辑,比如 jack 创建了一条 website 数据,但是,jack 数据在 userinfo表中被删除了,当websiteinfo 表 映射到 userinfo表查找 jack这条数据时,如果找不到,就忽略。
添加一个Hibernate 的注解
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = true)<span style="color:#ff0000;">@NotFound(action=NotFoundAction.IGNORE)</span>@JoinColumn(name = "USER_ID")public UserInfo getUserId() {return this.userId;}public void setUserId(UserInfo userId) {this.userId = userId;}
0 0
- Hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常No row with the given identifier exists 解决方法
- hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常:No row with the given identifier exists
- Hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常No row with the given identifier exists
- Hibernate异常No row with the given identifier exists 解决方法
- Hibernate异常No row with the given identifier exists 解决方法
- No row with the given identifier exists异常解决
- Hibernate: No row with the given identifier exists
- Hibernate: No row with the given identifier exists错误
- Hibernate: No row with the given identifier exists
- Hibernate中No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- org.hibernate.ObjectNotFoundException: No row with the given identifier exists
- WINAPI 函数 WaitForSingleObject(2)
- 汇总下几个IP计算/转换的shell小脚本
- JQuery中$.ajax()方法参数详解
- WaitForSingleObject(3)
- oracle undo 读书笔记
- Hibernate异常:No row with the given identifier exists
- 第十四周项目二—带姓名的成绩单读取数据操作版
- Mining Big Data using Weka 3 利用weka3挖掘大数据
- 通过漫画轻松掌握HDFS工作原理
- jni中char *的使用
- 内存泄漏与内存溢出
- nginx https 双向认证证书创建与配置
- IOS开发---C语言-⑦逻辑运算符和位运算符
- asp.net MVC中的tip