net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
来源:互联网 发布:武器发射工程 知乎 编辑:程序博客网 时间:2024/06/15 13:19
使用hibernate容易出现该问题,主要是由于pojo类属性存在级联关系。比如说员工和部门,在员工表里面有部门属性,而在部门表里面有个员工集合,这样就存在了嵌套引用的问题了,就会抛出这个异常。
解决方法很简单,在将每个对象转为json对象的时候用setExcludes函数将级联的属性去除掉就可以了,如下面:
1 //得到所有部门 2 //返回json对象字符串 3 public String getAllDep(){ 4 List list = deptDAO.findAll(); 5 JsonConfig config = new JsonConfig(); 6 config.setExcludes(new String[]{"emps"});//除去emps属性 7 String json = JSONArray.fromObject(list, config).toString(); 8 return json; 9 }10 11 //得到所有员工12 public String getAllEmp(int id){13 List list = empDAO.findByProperty("dept.deptId", id);14 JsonConfig config = new JsonConfig();15 config.setExcludes(new String[]{"dept"});//除去dept属性16 String json = JSONArray.fromObject(list, config).toString();17 return json;18 }
*********************************************第二种方法******************************************
自己写for循环把关联参数设置为null
0 0
- 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!错误解决方案
- 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!
- 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中net.sf.json.JSONException: There is a cycle in the hierarchy!的解决
- Json解析时出现net.sf.json.JSONException: There is a cycle in the hierarchy!42
- 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!
- 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异常的解决方法
- net.sf.json.JSONException: There is a cycle in the hierarchy!
- EasyUI表单验证,自定义插件验证,自定义js插件验证,远程验证,常见手机号,中英文,qq等验证规则验证
- Lua_Table_读取配置及取数据
- Linux C代码实现cgi shell
- 数字统计
- 如何优化myeclipse
- net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
- 库文件支持的arm64指令集架构的方法
- 第二章 C语言概述
- git提取出两个版本之间的差异文件并打包
- Eclipse查看jar中编译后的class文件注释显示乱码解决方法
- KMP算法
- Chartdirector variables addExtraField2
- java中Class.forName的作用
- Linux中环境变量文件及配置