---
title: "解决hibernate采用双向关联时生成JSON出错的问题"
author: "menuhin"
date: "2009-12-08T09:24:19Z"
tags: [".net", "Hibernate", "json"]
categories: ["企业架构"]
slug: "hibernate-json"
draft: false
lastmod: "2009-12-08T09:24:19Z"
id: 543825
url: "https://menuhin.iteye.com/blog/543825"
---

由于hibernate是采用双向关联，所以在生成JSON对象时会引起嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。
解决办法

```java

JsonConfig jsonConfig=new JsonConfig();
jsonConfig.setIgnoreDefaultExcludes(false);      jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); 

```

这样问题是解决了，但对这种解决办法的具体原理还没了解透，哪位路过的达人帮忙解释下！