json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
来源:互联网 发布:2017年气象灾害数据 编辑:程序博客网 时间:2024/05/22 07:45
因为项目中使用了AJAX技术,JAR包为:json-lib.jar, 在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题:
net.sf.json.JSONException: There is a cycle in the hierarchy!
at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97)
at net.sf.json.JSONObject._fromBean(JSONObject.java:857)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONObject._processValue(JSONObject.java:2774)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2798)
at net.sf.json.JSONObject.setValue(JSONObject.java:1507)
at net.sf.json.JSONObject._fromBean(JSONObject.java:940)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONObject._processValue(JSONObject.java:2774)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2798)
at net.sf.json.JSONObject.setValue(JSONObject.java:1507)
at net.sf.json.JSONObject._fromBean(JSONObject.java:940)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONObject._processValue(JSONObject.java:2774)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2798)
at net.sf.json.JSONObject.setValue(JSONObject.java:1507)
at net.sf.json.JSONObject._fromBean(JSONObject.java:940)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.sf.json.JSONObject._processValue(JSONObject.java:2774)
at net.sf.json.JSONObject._setInternal(JSONObject.java:2798)
at net.sf.json.JSONObject.setValue(JSONObject.java:1507)
at net.sf.json.JSONObject._fromBean(JSONObject.java:940)
at net.sf.json.JSONObject.fromObject(JSONObject.java:192)
at net.yanhl.iouser.action.IOUserAction.loadUser(IOUserAction.java:142)
因为Hibernate中设置了自身关联:
Iouser.hbm.xml:
<many-to-one name="group" class="net.yanhl.iouser.pojo.GroupRelation" lazy="false" cascade="none">
<column name="group_id" />
</many-to-one>
//设置自身关联的组对象
public class GroupRelation implements Serializable {
private static final long serialVersionUID = 6202253180943473205L;
private Integer id;// 主键ID
private Integer creatorId;// 创建人
private Date createDate;// 创建日期
private String groupName;// 组名称
private GroupRelation parentGroup;
private Set<GroupRelation> childGroups = new HashSet<GroupRelation>();
<many-to-one name="parentGroup" column="parent_id" lazy="false"
class="net.yanhl.iouser.pojo.GroupRelation">
</many-to-one>
<set name="childGroups" cascade="save-update" inverse="true">
<key column="parent_id"></key>
<one-to-many class="net.yanhl.iouser.pojo.GroupRelation" />
</set>
起初想通过hibernate来解决问题,就是想过滤掉自身关联后来查资料发现不可能实现,最后找到通过JSON-LIB来过滤关联的集合属性,代码如下:
JsonConfig config = new JsonConfig();
config.setJsonPropertyFilter(new PropertyFilter(){
public boolean apply(Object source, String name, Object value) {
if(name.equals("parentGroup") || name.equals("childGroups")) {
return true;
} else {
return false;
}
}
});
Iouser user = (Iouser) getBaseManager().get(Iouser.class, iouserId);
JSONObject jsonObject = JSONObject.fromObject(user, config);
当JSON-LIB解析JAVABEAN时过滤掉parentGroup、childGroups这两个属性,重新启动服务,pass
- json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
- json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
- net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决方法
- Json解析时出现net.sf.json.JSONException: There is a cycle in the hierarchy!42
- net.sf.json.JSONException: There is a cycle in the hierarchy异常,解决方法
- net.sf.json.JSONException: There is a cycle in the hierarchy! 异常
- net.sf.json.JSONException: There is a cycle in the hierarchy! 异常解决
- net.sf.json.JSONException: There is a cycle in the hierarchy异常处理
- json中net.sf.json.JSONException: There is a cycle in the hierarchy!的解决
- net.sf.json.JSONException: There is a cycle in the hierarchy! 错误产生的原因!
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy
- jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy!
- JSON处理Hibernate实体类net.sf.json.JSONException: There is a cycle in the hierarchy异常
- json与Java对象转化出现net.sf.json.JSONException: There is a cycle in the hierarchy!问题
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- .net学习笔记
- 创建一个有趣的Silverlight视频播放控件
- 关于emgu cv中无法加载cxcore110.dll的问题
- 数字家庭 (一) 开机
- 扩频通信的可行性
- json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法
- NHibernate.Burrow1.01GA 不能运行的解决办法
- Java 调用外部进程
- 关于comip.h(690)./comip.h(195) 编译错误的修改
- 一步一步创建一个Vista“忙”鼠标一样的Silverlight控件
- 本国货币贬值对经济的影响
- linux的网络安装和自动化安装
- JAVA将去向何方?
- Monospace/Fixed Width Programmer's Fonts