hibernate项目中报了这么一个错,指Object→json时候,Object下有引用对象导致的循环调用。
上次遇到过用,jsonconfig进行设置即可解决问题,前文有讲过,Object→json。
但是今天,Object下有一个引用对象需要使用,所以对Object引用对象的引用对象设置了jsonconfig。
这个循环问题就解决不了了。
16:18:58,928 INFO JSONObject:769 - Property 'autoClear' of class org.hibernate.internal.SessionImpl has no read method. SKIPPED
16:18:58,989 ERROR DefaultDispatcherErrorHandler:42 - Exception occurred during processing request: There is a cycle in the hierarchy!
net.sf.json.JSONException: There is a cycle in the hierarchy!
at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97)
at net.sf.json.JSONObject._fromBean(JSONObject.java:657)
at net.sf.json.JSONObject.fromObject(JSONObject.java:172)
at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:274)
at net.sf.json.JSONObject._processValue(JSONObject.java:2655)
at net.sf.json.JSONObject.processValue(JSONObject.java:2721)
at net.sf.json.JSONObject.setInternal(JSONObject.java:2736)
at net.sf.json.JSONObject.setValue(JSONObject.java:1424)
解决:使用debug进去后发现,在转json的时候Object的引用对象还没有加载,hibernate的懒加载是问题所在。
在object的引用对象加:lazy=false .页面可以正常显示。