前言:

  在一次项目中,分页查询公告列表信息后,在遍历查询到的公告列表时出现了死循环“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. B-generator 1_2019牛客暑期多校训练营(第五场)

    题意 给出\(x0,x1,a,b\), \(x_i = a\cdot x_{i-1} + b\cdot x_{i-2}\),问\(x_n取模mod\) 题解 用十进制快速幂,二进制快速幂是每到下一位就 ...

  2. POJ-1511 Invitation Cards( 最短路,spfa )

    题目链接:http://poj.org/problem?id=1511 Description In the age of television, not many people attend the ...

  3. lightoj 1158 - Anagram Division(记忆化搜索+状压)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1158 题解:这题看起来就像是记忆搜索,由于s很少最多就10位所以可以考虑用状压 ...

  4. CodeForces 311 B Cats Transport 斜率优化DP

    题目传送门 题意:现在有n座山峰,现在 i-1 与 i 座山峰有 di长的路,现在有m个宠物, 分别在hi座山峰,第ti秒之后可以被带走,现在有p个人,每个人会从1号山峰走到n号山峰,速度1m/s.现 ...

  5. 解决flutter:unable to find valid certification path to requested target 的问题

    1.问题 周末在家想搞搞flutter,家里电脑是windows的,按照官网教程一步步安装好以后,创建flutter工程,点击运行,一片红色弹出来,WTF? PKIX path building fa ...

  6. java多线程之ThreadPoolExecutor

    ThreadPoolExecutor类 简介   java.uitl.concurrent.ThreadPoolExecutor类是线程池中最核心的一个类,因此如果要透彻地了解Java中的线程池,必须 ...

  7. [币严BIZZAN区块链]数字货币交易所钱包对接之比特币(BTC)

    在币严BIZZAN开发数字货币交易所的过程中,一共有两大难点,一个是高速撮合交易引擎,另一个是钱包对接,这两者是我们团队以前没有接触过的.这个系列的文章主要介绍数字货币交易所钱包对接实现技术.第一个要 ...

  8. 固定定位下的div水平居中

    发现了一个之前未留意的知识点,做个笔记. 当一个块级元素的父元素开启了flex布局后,我们可以很轻松的将这个元素居中对齐,可以在父元素上加 justify-content: center; align ...

  9. 简单说一下你对http和https的理解

    http是一种超文本传输协议,传输的数据都是未加密的,也就是显示在明面上的,是现在互联网上应用最为广泛的一种网络协议,相对来说不太安全,但是所需成本很小.http一般的端口号为80. https则是具 ...

  10. Winforn中设置ZedGraph曲线图的属性、坐标轴属性、刻度属性

    场景 C#窗体应用中使用ZedGraph曲线插件绘制图表: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/99716066 在上面 ...