hibernate错误:org.apache.struts2.json.JSONWriter can not access a member of class
org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
with modifiers "public"
解释是当action执行完,return success返回xml文件后,前提是你设置了懒加载之后,hibernate自动为你懒加载的实体增加两个属性,(hibernateLazyInitializer,handler)这样如果你在xml文件中不过滤这两个属性就会报以上的错误,
主要原因:返回一个有懒加载对象的时候出现了错误,网上查了下可以在pojo中生成一个构造函数,不包括我们的懒加载对象,因为懒加载这个对象属性只是一个代理对象,如果json直接当作一个存在的属性去序列化就会出现错误
贴上action代码
package com.shinowit.actions; import com.opensymphony.xwork2.ActionSupport; import com.shinowit.dao.BaseDAO; import com.shinowit.entity.TMeMerchandiseInfo; import com.shinowit.tools.Cherset; import com.shinowit.tools.CommonQuery; import javax.annotation.Resource; import java.util.List; /** * Created by Administrator on 2014/11/13. */ public class TMeMerchandiseInfoAction extends ActionSupport{ @Resource private BaseDAO<TMeMerchandiseInfo> dao; private List<TMeMerchandiseInfo> tmmiList; private TMeMerchandiseInfo TMMI; private String code; private String codeName; private String msg; private int page; private int limit; private int rowCount; public String query(){ CommonQuery cq = new CommonQuery(); Cherset c =new Cherset(); code=c.charSet(code); codeName=c.charSet(codeName); String hql = cq.haveCodeHql("TMeMerchandiseInfo",code,codeName); String hqlCount = cq.haveCodeHqlCount("TMeMerchandiseInfo",code,codeName); tmmiList=dao.queryForPage(hql,page,limit); rowCount=dao.queryRecordCount(hqlCount); return SUCCESS; } }
xml代码:
<action name="tMeMerchandiseInfoQuery" class="com.shinowit.actions.TMeMerchandiseInfoAction" method="query"> <result type="json" > <param name="excludeProperties"> tmmiList.*hibernateLazyInitializer,tmmiList.*handler </param> </result> </action>
过滤掉这两个属性就可以了。