日期:2014-05-18  浏览次数:20706 次

Struts2 json put对象的时候出错
加了 lazy="false" 也不行。
不管是单表 还是连表 都不行。。。。
值是有获取到,

出错信息:
有两个:
第一个 是说我id有问题。。。无语


第二个:


HTTP Status 500 - org.apache.struts2.json.JSONExceptionorg.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.shop.bean.Product.carts, no session or session was closed

type Exception report

message org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.shop.bean.Product.carts, no session or session was closed

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.shop.bean.Product.carts, no session or session was closed
org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:246)
org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
org.apache.struts2.json.JSONWriter.map(JSONWriter.java:437)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:154)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:367)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:271)
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(Defa
JSON 对象 Struts session 异常

------解决方案--------------------
没什么说的,验证加载的问题。
明显是需要转换为json的对象中有一个子对象,这个子对象有些属性因为延迟加载的关系,没有初始化,导致框架转JSON报 一个JAVA文件里写两个类和两个文件各写一个类有什么区别?该怎么解决