The project uses Ajax technology, jar package is: json-lib.jar, encountered a problem related to JSON-LIB and hibernate in the development process:
Net. SF. JSON. jsonexception: there is a cycle in the hierarchy!
At net. SF. JSON. util. cycledetectionstrategy $ strictcycledetectionstrategy. handlerepeatedreferenceasobject (cycledetectionstrategy.
A circular error occurs when the primary and Foreign keys are associated.
Filter needs to be set to remove Association
Java
public ModelAndView getRooms(HttpServletResponse response,@PathVariable Long hotelsid){ List<Room> roomList=roomService.findByHotelsid(hotelsid); JsonConfig jsonConfig = new JsonConfig(); jsonConfig.setJsonPropertyFilter(new net.sf.json.util.PropertyFilter(){ @Override public boolean apply(Object source, String name, Object value) { if(name.equals("hotels")){ return true; }else{ return false; } }}); JSONArray json=JSONArray.fromObject(roomList,jsonConfig); try { PrintWriter out=response.getWriter(); out.println(json.toString()); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } return null; }