org.hibernate.LazyInitializationException: could not initialize proxy - no Session异常解决

     org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    
    org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:132)
    org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:174)
    org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
    com.shop.model.Account_$$_javassist_0.getLogin(Account_$$_javassist_0.java)

    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


Account_$$_javassist_0.java:$$_javassist这是hibernate的懒加载标记(hibernate特有的

意思是说:查询product,但是其结构是这样的:

product(id,name,Category(id,name,Account(id,name)))

当查完product之后session已经关闭,但是程序还在查Account所以会报no Session异常


解决方案:可以直接设置Accountnull

                或者:设成黑名单:

public String queryJionCategory(){

    pageMap = new HashMap<String, Object>();
List<Product> productlist = productService.queryJoinCategory(model.getName(), page, rows);
pageMap.put("rows", productlist);
pageMap.put("total", productService.getCount(model.getName()));
return "jsonMap";
    }

<package name="shop" extends="json-default">
     <global-results>
           <result name="aindex">/WEB-INF/main/aindex.jsp</result>
     </global-results>

      <action name="category_*" class="categoryAction" method="{1}">
         <result name="index">/index.jsp</result>
         <!-- 
          必须添加json包,然后继承 json-default
         -->
         <result name="jsonMap" type="json">
                  <!--要转化成json对象的数据  -->
                  <param name="root">pageMap</param> 
                  <!-- 配置配置黑名单,过滤不需要的选项 ,
                                                                      支持正则表达式 :
                                 \d 一个数字;+ 一个或多个;? 0或者1;* 1或多;
                                 [ABC]:自定义类型,必须是ABC中的一个
                                 [^ABC]:自定义类型,不包括是ABC中的一个或多个
                                 .:是任意字符;
                  -->
                  <param name="excludeProperties">
                      rows\[\d+\]\.account\.pass,
                      rows\[\d+\]\.account\.name
                  </param>
         </result>
         <result name="stream" type="stream">
                <param name="inputName">inputStream</param>
          </result>
      </action>
      
      <action name="account_*" class="accountAction" method="{1}">
         <result name="index">/index.jsp</result>
         <result name="jsonList" type="json">
                  <!--要转化成json对象的数据  -->
                  <param name="root">jsonList</param> 
                  <param name="excludeProperties">
                      \[\d+\]\.pass,
                      \[\d+\]\.name
                  </param>
         </result>
      </action>
      <action name="product_*" class="productAction" method="{1}">
         <result name="index">/index.jsp</result>
         <result name="jsonMap" type="json">
                 <param name="root">pageMap</param> 
               
 <param name="excludeProperties">
                     
rows\[\d+\]\.category\.account,
                      rows\[\d+\]\.date
                  </param>
         </result>
      </action>
      <action name="send_*_*" class="sendAction">
         <result name="send">/WEB-INF/{1}/{2}.jsp</result>
      </action>
  </package>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值