`

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

阅读更多

说到底,就是外键关联引起的问题。

 

问题产生原因:
有一个对象A,关联了对象B ,关联关系可以使 ManyToOne,OneToOne等,如果我们在数据库中清除了B对象,但是B对象还在A表中存在外键,这时候Hibernate检查这个关系的时候,会报出这个异常。但是A与B在数据库为范围内不能耦合过紧,只能pojo中建立关联关系,此时要注意,清除A表中的外键,可以解决此问题,一般的垃圾数据会造成业务系统不能正常运转。

第二个原因:
查询的时候,假设对象A与B有着一对一的关系,一般我们配置
@OneToOne
@JoinColumn(name = "xxx"),如果B被删除了,但是A中还维护这个外键关系
要配置
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "xxx")
的模式,不知道为什么默认不是lazy的,还要配置一下fetch = FetchType.LAZY

分享到:
评论

相关推荐

    Hibernate中get和load方法的区别以及close(),clear()、evict()等的区别

    Hibernate Session中的 flush方法的作用 ...load方式检索不到的话会抛出org.hibernate.ObjectNotFoundException异常 get方法检索不到的话会返回null 2.从检索执行机制上对比: get方法和find方法都是直接从数据库中检索

    hibernate操作数据库笔记

    //该方法将到classpath下解析hibernate.cfg.xml中的配置,如果不用Hibernate默认的配置文件名和路径,可在该方法中指定Hibernate配置文件的名称和路径 2.用Configuration对象获取SessionFactory和Session对象:...

    java的ejb.jar包

    javax.ejb.ObjectNotFoundException.class javax.ejb.RemoveException.class javax.ejb.SessionBean.class javax.ejb.SessionContext.class javax.ejb.SessionSynchronization.class javax.ejb.TimedObject.class ...

    javax.ejb.jar下载

    javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....

    jdbc基础和参考

    3.hibernate的配置文件(hibernate.cfg.xml)得存在 4.POJO.hbm.xml文件存在 5.hibernate的jar包以及数据库的驱动包存在 Hibernate的编程: 1.构建Configuration对象读取配置文件 2.读取映射文件 3.构建SessionFactory...

    javax.ejb.rar

    javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....

    javax.ejb.jar

    javax.ejb.ObjectNotFoundException.class javax.ejb.PostActivate.class javax.ejb.PrePassivate.class javax.ejb.Remote.class javax.ejb.RemoteHome.class javax.ejb.Remove.class javax.ejb.RemoveException....

Global site tag (gtag.js) - Google Analytics