There is a cycle in the hierarchy解决
前言:
在一次项目中,分页查询公告列表信息后,在遍历查询到的公告列表时出现了死循环“There is a cycle in the hierarchy”错误,分析原因是因为在公告实体类中包含了商铺对象导致,所以在遍历的时候需要过滤掉商铺这个字段。
代码示例:
公告实体类
/**
*
* 电商-公告
* EshopNotice entity.*/
@Entity
@Table(name = "eshop_notice")
@JsonIgnoreProperties(value={"shop"})
public class EshopNotice implements java.io.Serializable { // Fields // 系统ID
private String sysid; //时间戳记
private String tstamp; // 操作日期
private String operationDateTime; // 操作员
private String operator; /**
* 商铺
*/
private CoreCompany shop; /**
* 标题
*/
private String title; /**
* 内容
*/
private String content; /**
* 发布日期
*/
private String publishDatetime; /**
* 状态
*/
private String status; // Constructors
/** default constructor */
public EshopNotice() {
}
/** minimal constructor */
public EshopNotice(String tstamp, String operationDateTime, String operator, String title, String content,
String publishDatetime, String status) {
this.tstamp = tstamp;
this.operationDateTime = operationDateTime;
this.operator = operator;
this.title = title;
this.content = content;
this.publishDatetime = publishDatetime;
this.status = status;
} /** full constructor */
public EshopNotice(String tstamp, String operationDateTime, String operator, CoreCompany shop, String title,
String content, String publishDatetime, String status) {
this.tstamp = tstamp;
this.operationDateTime = operationDateTime;
this.operator = operator;
this.shop = shop;
this.title = title;
this.content = content;
this.publishDatetime = publishDatetime;
this.status = status;
} // Property accessors
@GenericGenerator(name = "generator", strategy = "uuid.hex")
@Id
@GeneratedValue(generator = "generator")
@Column(name = "sysid", unique = true, nullable = false, length = 32)
public String getSysid() {
return sysid;
}
public void setSysid(String sysid) {
this.sysid = sysid;
}
@Column(name = "tstamp", nullable = false, length = 20)
public String getTstamp() {
return tstamp;
}
public void setTstamp(String tstamp) {
this.tstamp = tstamp;
}
@Column(name = "operationdatetime", nullable = false, length = 20)
public String getOperationDateTime() {
return operationDateTime;
}
public void setOperationDateTime(String operationDateTime) {
this.operationDateTime = operationDateTime;
}
@Column(name = "operator", nullable = false, length = 32)
public String getOperator() {
return this.operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "shop", nullable = false)
public CoreCompany getShop() {
return this.shop;
}
public void setShop(CoreCompany shop) {
this.shop = shop;
}
@Column(name = "title", nullable = false, length = 128)
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
@Column(name = "content", nullable = false, length = 2000)
public String getContent() {
return this.content;
}
public void setContent(String content) {
this.content = content;
}
@Column(name = "publishdatetime", nullable = false, length = 20)
public String getPublishDatetime() {
return publishDatetime;
}
public void setPublishDatetime(String publishDatetime) {
this.publishDatetime = publishDatetime;
}
@Column(name = "status", nullable = false, length = 32)
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
分页查询遍历
@RequestMapping("/listPage.html")
public JSONTableDateView noticeList(HttpServletRequest request,PageQuery pageQuery) {
CoreMember member=(CoreMember)request.getSession().getAttribute("member");
CoreCompany company=coreCompanyService.getByMemberId(member.getSysid());
//分页查询
PageResults<EshopNotice> pageResults = noticeService.noticeList(pageQuery,company.getSysid());
//设置页面参数
JSONArray data = new JSONArray();
for(EshopNotice eshopNotice : pageResults.getResults()){
JsonConfig jsonConfig=new JsonConfig();
jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
@Override
public boolean apply(Object arg0, String arg1, Object arg2) {
//过滤段公告中的shop字段,否则会无限死循环
if (arg1.equals("shop") ) {
return true;
} else {
return false;
}
}
});
JSONObject dataTemp =JSONObject.fromObject(eshopNotice,jsonConfig);
dataTemp.put("title", eshopNotice.getTitle());
dataTemp.put("content", eshopNotice.getContent());
if(eshopNotice.getStatus().equals("00")){
dataTemp.put("status","申请");
}else{
dataTemp.put("status","审核通过");
}
dataTemp.put("publishDatetime",eshopNotice.getPublishDatetime());
dataTemp.put("sysid", eshopNotice.getSysid());
data.add(dataTemp);
}
JSONTableDateView jSONTableDateView = new JSONTableDateView(pageQuery, pageResults, data);
return jSONTableDateView;
}
There is a cycle in the hierarchy解决的更多相关文章
- 使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法
在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常. 意思是出现了死循环,也就是Model之间有循环包含关系: ...
- atitit.解决net.sf.json.JSONException There is a cycle in the hierarchy
atitit.解决net.sf.json.JSONException There is a cycle in the hierarchy 1. 环境:使用hibernate4跟个,,要不个哪的对象系列 ...
- hibernate:There is a cycle in the hierarchy! 造成死循环解决办法
下面是报的异常:在网上搜了关于:There is a cycle in the hierarchy!,才知道原来是因为死循环造成的!解决了好久,没有成功,后台不得已请教老大,老大说是因为在使用JSON ...
- json:There is a cycle in the hierarchy!
在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常. 意思是出现了死循环,也就是Model之间有循环包含关系: 解决 ...
- net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案
net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案 今天在用List集合转换成json数组的时候发生了这个错误,这个 ...
- net.sf.json.JSONException: There is a cycle in the hierarchy!
因为项目中使用了AJAX技术,jar包为:json-lib.jar,在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题: 如hibernate延迟加载错误,这都是些老问题了,一看就知 ...
- There is a cycle in the hierarchy! role对象此时是什么错误
There is a cycle in the hierarchy! role对象此时是什么错误
- net.sf.json.JSONException: There is a cycle in the hierarchy!的解决办法
使用Hibernate manytoone属性关联主表的时候,如果使用JSONArray把pojo对象转换成json对象时,很容易出现循环的异常.解决的办法就是, 在转换json对象时忽略manyto ...
- JSON解析关联类型发生死循环 There is a cycle in the hierarchy!
解决办法是忽略掉关联类型的数据,使用jsonConfig进行配置,代码如下: JsonConfig jsonConfig = new JsonConfig(); //建立配置文件 jsonConfi ...
随机推荐
- 关卡界面中个人信息随解锁关卡的移动(CocosCreator)
推荐阅读: 我的CSDN 我的博客园 QQ群:704621321 1.功能描述 在关卡很多的游戏里面,我们一般使用滑动来向玩家展示所有的关卡,为了清楚的让用户看到自己当前所在的关卡, ...
- 使用python发生邮箱
1.在使用邮箱登陆需要在邮箱内开启SMTP服务 2.注意在代码中登陆程序使用的密码为第三方授权登陆码,QQ邮箱为系统提供的授权码 网易邮箱为自己设置的授权码 QQ邮箱模拟 import smtplib ...
- Codeforces Round #504 E - Down or Right 交互题
1023E 题意: 交互题.在一个有障碍地图中,问如何走才能从(1,1)走到(n,n),只能向右或者向左走.每次询问两个点,回复你这两个点能不能走通. 思路: 只用最多2*n-2次询问.从(1,1), ...
- BZOJ1878[SDOI2009]HH的项链+莫队算法模板
题意:多次询问,求在一个区间中,有多少种珠子: 思路:莫队算法模板题目: 参考:https://www.cnblogs.com/RabbitHu/p/MoDuiTutorial.html #inclu ...
- 分层图 单调决策性DP
easy 写法. #include<bits/stdc++.h> using namespace std; #define Fopen freopen("_in.txt" ...
- hdu 3265 Posters(线段树+扫描线+面积并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3265 题意:给你一张挖了洞的墙纸贴在墙上,问你总面积有多少. 挖了洞后其实就是多了几个矩形墙纸,一张墙 ...
- U盘便携式hexo&博客搭建&极速纯净低bug主题推荐&部署到coding&SEO优化搜索
指南:U盘便携式hexo&博客搭建&极速纯净低bug主题推荐&部署到coding&SEO优化搜索 U盘便携式hexo随处写博客 简述:在任意一台联网的电脑上续写he ...
- 使用Spring Boot和RxJava的构建响应式REST API
我不打算解释什么是响应式编程,也不解释为什么要使用它.我希望你已经在其他地方了解过,如果没有,你可以使用Google去搜索它.在本文中,我将告诉您如何使用专门针对Spring Boot和RxJava的 ...
- 【Offer】[53-3] 【数组中数值和下标相等的元素】
题目描述 思路分析 测试用例 Java代码 代码链接 题目描述 假设一个单调递增的数组里的每个元素都是整数并且是唯一的.请编程实现一个函数,找出数组中任意一个数值等于其下标的元素.例如,在数组{-3, ...
- if __name__ = "main" 解释