前言:

  在一次项目中,分页查询公告列表信息后,在遍历查询到的公告列表时出现了死循环“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解决的更多相关文章

  1. 使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法

    在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常.   意思是出现了死循环,也就是Model之间有循环包含关系: ...

  2. 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跟个,,要不个哪的对象系列 ...

  3. hibernate:There is a cycle in the hierarchy! 造成死循环解决办法

    下面是报的异常:在网上搜了关于:There is a cycle in the hierarchy!,才知道原来是因为死循环造成的!解决了好久,没有成功,后台不得已请教老大,老大说是因为在使用JSON ...

  4. json:There is a cycle in the hierarchy!

    在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常. 意思是出现了死循环,也就是Model之间有循环包含关系: 解决 ...

  5. net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案

    net.sf.json.JSONException: There is a cycle in the hierarchy!错误解决方案 今天在用List集合转换成json数组的时候发生了这个错误,这个 ...

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

    因为项目中使用了AJAX技术,jar包为:json-lib.jar,在开发过程中遇到了一个JSON-LIB和Hibernate有关的问题: 如hibernate延迟加载错误,这都是些老问题了,一看就知 ...

  7. There is a cycle in the hierarchy! role对象此时是什么错误

    There is a cycle in the hierarchy! role对象此时是什么错误

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

    使用Hibernate manytoone属性关联主表的时候,如果使用JSONArray把pojo对象转换成json对象时,很容易出现循环的异常.解决的办法就是, 在转换json对象时忽略manyto ...

  9. JSON解析关联类型发生死循环 There is a cycle in the hierarchy!

    解决办法是忽略掉关联类型的数据,使用jsonConfig进行配置,代码如下: JsonConfig jsonConfig = new JsonConfig();  //建立配置文件 jsonConfi ...

随机推荐

  1. Delphi - cxGrid连接Oracle数据库 实现数据的增删改查

    cxGrid连接Oracle数据库 实现数据的增删改查 cxGrid连接Oracle数据库 1:通过OraSession连接数据库.OraDataSet实现OraSession和OraDataSour ...

  2. iOS仿写下厨房

    把之前简书的博客搬到博客园了,还是放在一个地方看着舒服. 先看一下做的效果,是不是还不错?(可以看一下早餐那块的轮播,上面盖着一个都是点点的图片,但是它不是和轮播一起滚动的,是盖在轮播上面的,需要在那 ...

  3. 使用GPU跑Tensorflow代码实录

    使用conda创建一个新的虚拟环境 输入 conda create -n intelligent-judge python=3.6 创建一个python版本为3.6的名字是intelligent-ju ...

  4. Redis数据类型的基本操作

    Redis数据类型的基本操作 一.string类型 1.设置value

  5. selenium webdriver (python)第三版.pdf

    转载自:http://download.csdn.net/detail/waiwaijsj/7214035 是原作者根据自己的经验整理的,很实用.

  6. P2059 [JLOI2013]卡牌游戏 概率DP

    link:https://www.luogu.org/problemnew/show/P2059 题意: 有n个人,类似约瑟夫环的形式踢人,但是报的数是不同的,是在给定的许多数中随机抽取,问最后第i个 ...

  7. 洛谷 P1070 道路游戏 DP

    P1070 道路游戏 题意: 有一个环,环上有n个工厂,每个工厂可以生产价格为x的零钱收割机器人,每个机器人在购买后可以沿着环最多走p条边,一秒走一条,每条边不同时间上出现的金币是不同的,问如何安排购 ...

  8. ccpc网赛 hdu6703 array(权值线段树

    http://acm.hdu.edu.cn/showproblem.php?pid=6703 大意:给一个n个元素的数组,其中所有元素都是不重复的[1,n]. 两种操作: 将pos位置元素+1e7 查 ...

  9. 牛客练习赛17 B-好位置

    传送门 题意:本来惯例中文题不解释的, 但是有些人不懂这个题意, 简单的来说, 就是s1每一个的每一个字符都可以和别的字符构成一个子串 == s2.  算了还是惯例中文题意不解释吧. 题解:其实以前写 ...

  10. 这一次,彻底弄懂 Promise 原理

    作者声明 本人将迁移至个人公众号「前端Q」及「掘金」平台写文章.博客园的文章将不再及时更新发布.欢迎大家关注公众号「前端Q」及我的掘金主页:https://juejin.im/user/5874526 ...