Hibernate异常No row with the given identifier exists 解决方法
来源:互联网 发布:config.php如何下载 编辑:程序博客网 时间:2024/06/05 03:54
产生此问题的原因:
有两张表,table1和table2.产生此问题的原因就是table1里做了关联<one-to-one>或者<many-to-one unique="true">(特殊的多对一映射,实际就是一对一)来关联table2.当hibernate查找的时候,table2里的数据没有与table1相匹配的,这样就会报No row with the given identifier exists这个错.(一句话,就是数据的
现在hibernate配置可以基于xml配置文件和注解方式,这两种方式都能发生这个异常xml配置文件解决方法:
- <many-to-one class="com.art.model.user.UserInfo" fetch="join" name="userInfo" >
- <column name="userId" unique="true"/>
- </many-to-one>
修改后的:
红色是修改的部分。意思是当对应的数据不存在时 忽略掉,用null值填充。该属性默认值:exception 。
- <many-to-one class="com.art.model.user.UserInfo" fetch="join" name="userInfo" not-found="ignore">
- <column name="userId" unique="true"/>
- </many-to-one>
注解配置解决方法:
使用hibernate 注解配置实体类的关联关系,在many-to-one,one-to-one关联中,一边引用自另一边的属性,如果属性值为某某的数据在数据库不存在了,hibernate默认会抛出异常。解决此问题,加上如下注解就可以了:
@NotFound(action=NotFoundAction.IGNORE),意思是找不到引用的外键数据时忽略,NotFound默认是exception
下面贴出hibernate 注解的实例代码- @Entity
- @Table(name = "ICT_COMPUTER_LOCATION")
- public class IctComputerLocation {
- private static final long serialVersionUID = 1L;
- private Integer id;
- /** IDC编号 */
- private String idcNum;
- private Integer ictBaseId;
- /** IctBase实体类 */
- private IctBase ictBase;
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- @Column(name = "ID")
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- @Column(name = "IDC_NUM")
- public String getIdcNum() {
- return idcNum;
- }
- public void setIdcNum(String idcNum) {
- this.idcNum = idcNum;
- }
- @Column(name = "ICT_BASE_ID")
- public Integer getIctBaseId() {
- return ictBaseId;
- }
- public void setIctBaseId(Integer ictBaseId) {
- this.ictBaseId = ictBaseId;
- }
- @ManyToOne(fetch = FetchType.LAZY)
- @JoinColumn(name = "ICT_BASE_ID", referencedColumnName = "ID", unique = false, nullable = false, insertable = false, updatable = false)
- @NotFound(action=NotFoundAction.IGNORE)
- public IctBase getIctBase() {
- return ictBase;
- }
- public void setIctBase(IctBase ictBase) {
- this.ictBase = ictBase;
- }
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异常解决
- No row with the given identifier exists 解决方法
- No row with the given identifier exists 解决方法
- No row with the given identifier exists 解决方法(集锦)
- No row with the given identifier exists 解决方法
- No row with the given identifier exists 解决方法
- No row with the given identifier exists 解决方法
- AIX系统学习之-ODM管理
- CRC16校验算法实现
- 程序员该有的艺术气质—SOLID原则
- IT人-不要一辈子靠技术生存
- 树控件多选类
- Hibernate异常No row with the given identifier exists 解决方法
- 通知的用法,传值
- 题解053-425(V13.02版本,711题)
- BUG系列:调用startActivityForResult()&onActivityResult()无响应
- [搜索] Solr (一) 简介及安装
- AIX系统错误之--磁盘错误
- 计算机视觉、机器学习相关领域论文和源代码大集合
- PAT(A) 1012
- Java仿windows记事本较完整版