Hibernate常见的错误异常

1.错误:object references an unsaved transient instance - save the transient instance before flushing:

com.xxxx.bean.java.Sysblog; nested exception is org.hibernate.TransientObjectException: object references an unsaved

transient instance - save the transient instance before flushing: com.xxx.bean.java.Sysblog

解决方法:没有可预期的实例,当然就要实例化对象

2.错误:Exceptionobject references an unsaved transient instance - save the transient instance before flushing:

src.persistent.Product......

解决方法:原因没有为某对象进行set设置, 如上边的这个就是某对象没有调用setProduct

3.错误:Illegal attempt to associate a collection with two open sessions......

解决方法:(hibernatesession提供了一级缓存,每个session,对同一个id进行两次load,不会发送两条sql给数据库,但是session关闭的

时候,一级缓存就失效了。

sysblogarticle.setAmount(new Long(sysblogcommentService.selcom(
                  sysblogarticle.getArticleid().toString()).size()));//通过文章id获取文章评论数
           sysblogarticle.setSysblogcomments(null);//关键
           sysblogarticleService.saveOrUpdate(sysblogarticle);//将文章中评论条数修改

 

posted on 2018-04-28 16:02  王甜甜的小摩托  阅读(133)  评论(0编辑  收藏  举报

导航