加了 lazy="false" 也不行。
不管是单表 还是连表 都不行。。。。
值是有获取到,
出错信息:
有两个:
第一个 是说我id有问题。。。无语

第二个:

HTTP Status 500 - 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
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报空指针。
解决的部分 1,取消延迟延迟加载 。基本不可取,对性能影响大
2,在service层手动调用get方法,。不可去,道理同上。
3,将po,vo分离,vo用于数据逻辑以及转换为JSON数据,PO做数据持久化处理。
好好去理解一下延迟加载。
另外好好理解一下po,vo,dto的区别,别把他们混一起。
------解决方案--------------------