json-lib 出现net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决办法

基于FPGA的 SelectIO IP核 的仿真验证-----( LVDS差分高速传输) SelectIO IP核 的仿真验证 阅读详情

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

/proc/sys/vm/max_map_count耗尽时,调用glibc 2.11.3 free()导致程序crash,问题追踪和解决 1. 问题 在客户环境下,当我们的程序消耗较大内存时,会偶尔crash。 通过gdb分析,程序core dump在malloc/free函数内。 当把/proc/sys/vm/max_map_count 从65530增加到131070,程序再也不crash。 相关命令 echo 131073 > /proc/sys/vm/max_map_count 2.  core 阅读详情

相关推荐

金融科技数据源

数字金融开放研究平台

平平淡淡,戒急用忍,一生学闭嘴。 1783

jQuery调用JSON时,net.sf.json.JSONException: There is a cycle in the hierarchy!

遇到了一些问题,如hibernate延迟加载错误,这都是老掉牙的问题了,一看就知道加个lazy=flase就OK了。想不到快要完成了又遇到了新的问题,JSON死循环,实在让人郁闷。异常如下: net.sf.json.JSONException: There is a cycle in the hierarchy!         at net.sf.json.util.CycleDet

沈荣荣的博客 576

WPF实战:利用Live Charts实现高性能动态曲线可视化

本文详细介绍了如何在WPF中使用Live Charts实现高性能动态曲线可视化,特别适用于工业监控和金融分析等实时数据场景。通过增量渲染、内存复用和硬件加速等核心技术,Live Charts能够高效处理高频数据更新,显著提升图表流畅度。文章提供了从基础实现到工业级优化的完整解决方案,帮助开发者应对各种性能挑战。

weixin_29189373的博客 420

net.sf.json.JSONException: There is a cycle in the hierarchy! 异常

问题: net.sf.json.JSONException: There is a cycle in the hierarchy!  at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java

zh921112的专栏 1812

无人机避障——感知篇(采用Mid360复现Fast-lio)

本文介绍了在Ubuntu 18.04和ROS Melodic环境下,使用Xavier-nx电脑和Livox Mid-360激光雷达编译和运行FAST-LIO工程的步骤,包括创建工作空间、编译驱动和FAST-LIO源码,以及运行launch文件进行建图的过程。

weixin_45390670的博客 3556

STM32水质检测小船设计

近年来水资源的监测与保护越来越受到政府部门的重视,抓好源头问题才能做好环境治理,因此建立完善的水环境监测系统是很有必要的。针对当前水环境参数监测中存在的各种问题,例如水质信息采集范围固定、灵活部署监测能力差、信息采集不够智能化、人机交互能力不足等,这些问题导致水环境监测设备不够灵活。 针对上述问题,本文设计了一款基于STM32的水环境监测小船,提出了一种灵活、智能的监测水环境信息的方式。本文将船体作为传感器和控制板的载体,具有可移动性,有利于灵活广泛的采集水环境信息。 本设计选用STM32F103C8T

m0_74026776的博客 1376

net.sf.json.JSONException: There is a cycle in the hierarchy异常的解决方法

以前遇到这个问题都是设下JsonConfig 的一个属性的:config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); 到后来才发现,这样不能从根源解决问题。后来在网上看到一个人写的博客,写的太棒了,转来跟大家分享下。 博客地址:http://chenjinglys.blog.163.com/blog/static

NBA_2011的专栏 2153

COMSOL仿真避坑指南:列管反应器模拟中多孔介质与化学反应设置的5个常见错误

本文详细解析了COMSOL仿真中列管反应器模拟的5个常见错误,包括多孔介质模型选择、化学反应接口配置、对流扩散方程处理、薄层热阻设置及网格独立性验证。特别针对多孔介质与化学反应设置的误区,提供了实用的判断标准和修正方法,帮助工程师避免计算偏差,提升仿真精度。

weixin_29597551的博客 334

net.sf.json.JSONException: There is a cycle in the hierarchy!

问题: net.sf.json.JSONException: There is a cycle in the hierarchy!  at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java

sivyer123的专栏 777

SPI扩展CAN方案:从寄存器配置到多路通信实战

本文详细介绍了SPI扩展CAN方案的实现方法,从寄存器配置到多路通信实战。通过使用MCP2517FD芯片和SPI接口,可低成本扩展多路CAN通道,适用于工业控制领域。文章涵盖硬件设计、寄存器配置、中断优化及性能调优等核心内容,帮助开发者高效解决设备节点过多的问题。

weixin_42657024的博客 366

Android Framework WMS全面概述和知识要点

WindowManagerService 类是整个 WMS 的核心大脑,处于系统服务层,负责协调和管理所有与窗口相关的操作。它在 Android 系统架构中起到承上启下的关键作用,向上对接应用层的窗口请求,向下与 SurfaceFlinger 等底层组件交互,确保窗口能够正确地在屏幕上显示和管理。

大模型大数据攻城狮的专栏 1806

json-lib出现There is a cycle in the hierarchy解决办法

问题的出现 如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。 解决办法 1.设置JSON-LIB让其过滤掉引起循环的字段。 JsonConfig config = new JsonC

Java18的专栏 1126

基于形状的模板匹配之候选点选择

基于形状的匹配匹配,顶层金字塔提取候选点

manuoo的专栏 2774

json中net.sf.json.JSONException: There is a cycle in the hierarchy!的解决

问题: net.sf.json.JSONException: There is a cycle in the hierarchy!  at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java

u011523968的专栏 480

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

错误 net.sf.json.JSONException: There is a cycle in the hierarchy!

问题: net.sf.json.JSONException: There is a cycle in the hierarchy!  at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java

xys_00 360

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

json解析过程中遇到net.sf.json.JSONException: There is a cycle in the hierarchy!问题

其一:根据原理来解决,如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。 举个例子:现在有实验(Lib)和类别(Libtype)两张表,每个实验都对应着一个类别,那么,在类别的POJO中,就会如下代码:  private I

java_zc的博客 677

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

JSON处理Hibernate实体类net.sf.json.JSONException: There is a cycle in the hierarchy异常

由于Hibernate中好多实体类都级联关系,也就是某个类,出现了别的类的引用对象充当属性。那么这样的话用JSON来进行处理会出现嵌套的异常:net.sf.json.JSONException: There is a cycle in the hierarchy异常。 在处理这个错误之前先看看普通的JSON处理数据示例 TProcessInfoDAO dao = new TProcessInf...

JavaCrazyer的ItEye(codewu.com)技术博客 188

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

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

weixin_34168700的博客 122

net.sf.json.JSONException: There is a cycle in the hierarchy!---数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛

问题: net.sf.json.JSONException: There is a cycle in the hierarchy!  at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java

CreateUser_ZUO的专栏 491

[转]JSON 转换异常 死循环 There is a cycle in the hierarchy

转载:http://blog.csdn.net/zhengbo0/article/details/8269148 问题: net.sf.json.JSONException: There is a cycle in the hierarchy!at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.han...

weixin_33770878的博客 157

使用jsonConfig对 object进行过滤

List accountList = accountService.query(); System.out.println(accountList); JsonConfig config = new JsonConfig(); config.setExcludes(new String[] { "name", "pass", "categories"

学习天地 1764

json-lib-2.4-jdk15.jar 报错 net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案(Hibern...

使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系。比如说员工和部门,在员工表里面有部门属性,而在部门表里面有个员工集合,这样就存在了嵌套引用的问题了,就会抛出这个异常。 解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面: 比如CityVo 里面有关联属性 ProvinceVo province 以及 地...

weixin_34362991的博客 182
上一篇: 使用jQuery绑定事件注意事项
下一篇: 推荐使用轻量级ajax框架-jQuery
mgqy
博客等级 码龄21年 49粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值