前言:

  在一次项目中,分页查询公告列表信息后,在遍历查询到的公告列表时出现了死循环“There is a cycle in the hierarchy”错误,分析原因是因为在公告实体类中包含了商铺对象导致,所以在遍历的时候需要过滤掉商铺这个字段。

代码示例:

公告实体类

  1. /**
  2. *
  3. * 电商-公告
  4. * EshopNotice entity.*/
  5. @Entity
  6. @Table(name = "eshop_notice")
  7. @JsonIgnoreProperties(value={"shop"})
  8. public class EshopNotice implements java.io.Serializable {
  9.  
  10. // Fields
  11.  
  12. // 系统ID
  13. private String sysid;
  14.  
  15. //时间戳记
  16. private String tstamp;
  17.  
  18. // 操作日期
  19. private String operationDateTime;
  20.  
  21. // 操作员
  22. private String operator;
  23.  
  24. /**
  25. * 商铺
  26. */
  27. private CoreCompany shop;
  28.  
  29. /**
  30. * 标题
  31. */
  32. private String title;
  33.  
  34. /**
  35. * 内容
  36. */
  37. private String content;
  38.  
  39. /**
  40. * 发布日期
  41. */
  42. private String publishDatetime;
  43.  
  44. /**
  45. * 状态
  46. */
  47. private String status;
  48.  
  49. // Constructors
  50. /** default constructor */
  51. public EshopNotice() {
  52. }
  53. /** minimal constructor */
  54. public EshopNotice(String tstamp, String operationDateTime, String operator, String title, String content,
  55. String publishDatetime, String status) {
  56. this.tstamp = tstamp;
  57. this.operationDateTime = operationDateTime;
  58. this.operator = operator;
  59. this.title = title;
  60. this.content = content;
  61. this.publishDatetime = publishDatetime;
  62. this.status = status;
  63. }
  64.  
  65. /** full constructor */
  66. public EshopNotice(String tstamp, String operationDateTime, String operator, CoreCompany shop, String title,
  67. String content, String publishDatetime, String status) {
  68. this.tstamp = tstamp;
  69. this.operationDateTime = operationDateTime;
  70. this.operator = operator;
  71. this.shop = shop;
  72. this.title = title;
  73. this.content = content;
  74. this.publishDatetime = publishDatetime;
  75. this.status = status;
  76. }
  77.  
  78. // Property accessors
  79. @GenericGenerator(name = "generator", strategy = "uuid.hex")
  80. @Id
  81. @GeneratedValue(generator = "generator")
  82. @Column(name = "sysid", unique = true, nullable = false, length = 32)
  83. public String getSysid() {
  84. return sysid;
  85. }
  86. public void setSysid(String sysid) {
  87. this.sysid = sysid;
  88. }
  89. @Column(name = "tstamp", nullable = false, length = 20)
  90. public String getTstamp() {
  91. return tstamp;
  92. }
  93. public void setTstamp(String tstamp) {
  94. this.tstamp = tstamp;
  95. }
  96. @Column(name = "operationdatetime", nullable = false, length = 20)
  97. public String getOperationDateTime() {
  98. return operationDateTime;
  99. }
  100. public void setOperationDateTime(String operationDateTime) {
  101. this.operationDateTime = operationDateTime;
  102. }
  103. @Column(name = "operator", nullable = false, length = 32)
  104. public String getOperator() {
  105. return this.operator;
  106. }
  107. public void setOperator(String operator) {
  108. this.operator = operator;
  109. }
  110. @ManyToOne(fetch = FetchType.LAZY)
  111. @JoinColumn(name = "shop", nullable = false)
  112. public CoreCompany getShop() {
  113. return this.shop;
  114. }
  115. public void setShop(CoreCompany shop) {
  116. this.shop = shop;
  117. }
  118. @Column(name = "title", nullable = false, length = 128)
  119. public String getTitle() {
  120. return this.title;
  121. }
  122. public void setTitle(String title) {
  123. this.title = title;
  124. }
  125. @Column(name = "content", nullable = false, length = 2000)
  126. public String getContent() {
  127. return this.content;
  128. }
  129. public void setContent(String content) {
  130. this.content = content;
  131. }
  132. @Column(name = "publishdatetime", nullable = false, length = 20)
  133. public String getPublishDatetime() {
  134. return publishDatetime;
  135. }
  136. public void setPublishDatetime(String publishDatetime) {
  137. this.publishDatetime = publishDatetime;
  138. }
  139. @Column(name = "status", nullable = false, length = 32)
  140. public String getStatus() {
  141. return this.status;
  142. }
  143. public void setStatus(String status) {
  144. this.status = status;
  145. }

分页查询遍历

  1. @RequestMapping("/listPage.html")
  2. public JSONTableDateView noticeList(HttpServletRequest request,PageQuery pageQuery) {
  3.  
  4. CoreMember member=(CoreMember)request.getSession().getAttribute("member");
  5. CoreCompany company=coreCompanyService.getByMemberId(member.getSysid());
  6.  
  7. //分页查询
  8. PageResults<EshopNotice> pageResults = noticeService.noticeList(pageQuery,company.getSysid());
  9. //设置页面参数
  10. JSONArray data = new JSONArray();
  11. for(EshopNotice eshopNotice : pageResults.getResults()){
  12. JsonConfig jsonConfig=new JsonConfig();
  13. jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
  14. @Override
  15. public boolean apply(Object arg0, String arg1, Object arg2) {
  16. //过滤段公告中的shop字段,否则会无限死循环
  17. if (arg1.equals("shop") ) {
  18. return true;
  19. } else {
  20. return false;
  21. }
  22. }
  23. });
  24. JSONObject dataTemp =JSONObject.fromObject(eshopNotice,jsonConfig);
  25. dataTemp.put("title", eshopNotice.getTitle());
  26. dataTemp.put("content", eshopNotice.getContent());
  27. if(eshopNotice.getStatus().equals("00")){
  28. dataTemp.put("status","申请");
  29. }else{
  30. dataTemp.put("status","审核通过");
  31. }
  32. dataTemp.put("publishDatetime",eshopNotice.getPublishDatetime());
  33. dataTemp.put("sysid", eshopNotice.getSysid());
  34. data.add(dataTemp);
  35. }
  36. JSONTableDateView jSONTableDateView = new JSONTableDateView(pageQuery, pageResults, data);
  37. return jSONTableDateView;
  38. }

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. Django之上传图片,分页,三级联动

    Django1.8.2中文文档:Django1.8.2中文文档 上传图片 配置上传文件保存目录 1)新建上传文件保存目录. 2)配置上传文件保存目录. 后台管理页面上传图片 1)设计模型类. 2)迁移 ...

  2. centos7yum安装mysql5.7

    https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-centos-7 https://typecodes. ...

  3. spring boot application 配置详情

    # =================================================================== # COMMON SPRING BOOT PROPERTIE ...

  4. Kubernetes 入门必备云原生发展简史

    作者|张磊 阿里云容器平台高级技术专家,CNCF 官方大使 "未来的软件一定是生长于云上的"这是云原生理念的最核心假设.而所谓"云原生",实际上就是在定义一条能 ...

  5. Mysql分区实战

    一,什么是数据库分区 前段时间写过一篇关于MySQL分表的的文章,下面来说一下什么是数据库分区,以mysql为例.mysql数据库中的数据是以文件的形势存在磁盘上的,默认放在/mysql/data下面 ...

  6. Java面试-List中的sort详细解读

    最近看了一些排序相关的文章,因此比较好奇,Java中的排序是如何做的.本片文章介绍的是JDK1.8,List中的sort方法. 先来看看List中的sort是怎么写的: @SuppressWarnin ...

  7. DAX 第八篇:表连接

    表连接是指两张表根据关联字段,组合成一个数据集.表连接不仅可以利用数据模型中已有的关系,而且可以利用DAX表达式基于表的任意列定义连接条件.因此,在DAX中,实现表与表之间的连接,有两种方式: 第一种 ...

  8. [ERR] 1118 - Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.

    昨天,在测试新的数据库时,迁移表遇到了这个问题.现在记录一下解决方案. 1.在配置文件中添加关闭严格模式的配置:sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS ...

  9. odoo12从零开始:三、2)odoo模型层

    前言 上一篇文章(创建你的第一个应用模块(module))已经大致描述了odoo的模型层(model)和视图层(view),这一篇文章,我们将系统地介绍有关于model的知识,其中包括: 1.模型的类 ...

  10. [币严区块链]简单易懂的以太坊(ETH)智能合约开发入门教程

    以太坊(Ethereum)是一提供个智能合约(smart contract)功能的公共区块链(BlockChain)平台. 本文介绍了一个简单的以太坊智能合约的开发过程. 开发环境 在以太坊上开发应用 ...