因为项目中使用了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:

//设置自身关联的组对象

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 childGroups = new HashSet();

起初想通过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

出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法相关推荐

  1. 报错问题解决:net.sf.json.JSONException: There is a cycle in the hierarchy!

    若非java这一块相关的战友,直接点评即可,无需阅读文章 报错问题: net.sf.json.JSONException: There is a cycle in the hierarchy! atn ...

  2. json数据转换异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException

    json数据转换异常:net.sf.json.JSONException: java.lang.reflect.InvocationTargetException 参考文章: (1)json数据转换异 ...

  3. 扰人的异常:net.sf.json.JSONException: Object is null

    菜鸟的笔记-----异常1 Method public java.lang.String org.apache.commons.lang.exception.NestableRuntimeExcept ...

  4. JSONException: There is a cycle in the hierarchy

    见:https://blog.csdn.net/testcs_dn/article/details/24694709 http://www.cnblogs.com/az19870227/archive ...

  5. nested exception is java.lang.NoClassDefFoundError: org/codehaus/jettison/json/JSONObject异常的解决办法

    nested exception is java.lang.NoClassDefFoundError: org/codehaus/jettison/json/JSONObject异常的解决办法 参考文 ...

  6. Unable to evaluate the expression Method threw ‘net.sf.json.JSONException‘ exception.

    json格式字符串含有null值,用JSONArray.fromObject转换为json数组时报错 --------------------------------- 问题出现 一天突然发现平时正常 ...

  7. net.sf.json.JSONException: Unterminated string at character 1801

    在解析json格式数据时,出现此错误.错误意思是没有终结的字符串.原因是原始的字符串的末尾的一段子字符串未处理.

  8. hibernate报错 net.sf.json.util.CycleDetectionStrategy$StrictionStrategyRepeatedReferenceAsObject

    =执行{+com.j.serviceimpl.ArticleServiceimpl+}类的的+97+行的+selectAllByIdS+()方法, ===异常信息为:{} There is a cyc ...

  9. net.sf.json.JSONObject处理 null 字符串的一些坑

    转: net.sf.json.JSONObject处理 "null" 字符串的一些坑 2018年05月02日 16:41:25 大白能 阅读数:7026 版权声明:本文为博主原创文 ...

  10. org.json.JSONException: A JSONObject text must begin with #39;{#39; at character 1 of {解决方法...

    在使用java读取一个本地的json配置文件的时候,产生了这个异常:org.json.JSONException: A JSONObject text must begin with '{' at c ...

最新文章

  1. 【C/C++语言入门篇】-- 文件操作
  2. LINQ之路系列博客后记
  3. 最小表达式_C# 09.找最大和最小的数字
  4. MapReduce整体架构分析
  5. 绝对的干货大放送:常用正则表达式收集大全
  6. Object-C,NSSet,不可变集合
  7. 【产品经验谈】详解Axure中的默认元件库
  8. 地统计学插值 | IDW(反距离)和Kriging(克里金)
  9. C++卡常数之内存优化
  10. 代码评审(CR)实践指南
  11. 城镇化率与世界平均水平相当 质量不高问题突出
  12. 知识图谱之WordNet
  13. IDEA中Dubugger设置
  14. web注释@WebService,@WebMethod,@Oneway,@WebParam
  15. fortigate防火墙虚拟机版本的使用
  16. RabbitMQ - 4种Exchange类型
  17. 【UI自动化设计模式】超越 Page Objects:使用Serenity和ScreenplayPattern实现新一代的自动化测试
  18. 游戏运营是什么?运营专员需要具备什么能力?
  19. 数据监控难点之实时监测
  20. Linux系统编程之捕捉SIGCHLD

热门文章

  1. 谈谈学完Asp.net 中的自定义控件后的感受
  2. 给.Net程序员和WEB程序员建议 (转自CSDN)
  3. Visio是一个很好的UML建模软件和一个很好的制图软件
  4. English trip V1 - 2.Don't Do That Teacher:Patrick Key: 祈使句(imperatives)
  5. haoi2018奇怪的背包题解
  6. 1.Thinkphp入门--框架介绍
  7. 常见SMTP发送失败原因列表
  8. LA 6047Perfect Matching(回文串哈希)
  9. java.net.bindexception: address already in use: jvm_bind:8080
  10. DataFrame基础操作