zoukankan      html  css  js  c++  java
  • 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);//将文章中评论条数修改

  • 相关阅读:
    HeidiSQL
    PostgreSQL
    MariaDB
    NLog
    0 vs null
    忘带手机的那么一天
    江城子·己亥年戊辰月丁丑日话凄凉
    单体 VS 微服务
    java面向对象(四)之重写、重载
    java面向对象(三)之抽象类,接口,向上转型
  • 原文地址:https://www.cnblogs.com/jingxiaopu/p/9310428.html
Copyright © 2011-2022 走看看