Hibernate的many-to-one双向关联中,查询many方时会将one方数据顺带着查询,同时one中会有List<Many>,然后又会去查Many中的数据...

周而复始,结果json解析失败。 

解决方法咧,可以通过JsonConfig的setExcludes方法设置过滤字段

1 public class One {
2     private int id;
3     List<Many> manyList;
4          ...
5 }
1 public class Many {
2     private int id;
3     private One one;
4          ...
5 }
1 String HQLStr = "from Many";
1 JsonConfig jsonConfig = new JsonConfig();
2 jsonConfig.setExcludes(new String[]{"manyList"});//关键在这,过滤掉这个
3 JSONArray result= new JSONArray();
4 result.add(tempList, jsonConfig);//tempList是通过Hibernate查询的结果集

 

相关文章:

  • 2022-12-23
  • 2022-01-29
  • 2021-05-26
  • 2021-05-09
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2022-12-23
  • 2021-07-11
相关资源
相似解决方案