我正在使用Spring数据的休息服务。当我从单个表中获取数据时,它以json格式返回正确的结果。但是当我在使用hibernate的实体之间使用多对多关联时,我得到了一个不可接受的结果,并在chrome的控制台中出现以下错误。
Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
我的结果看起来只有一行重复,并且特别是通过关联在新生成的表中使用的字段。
[{"id":7,"name":"Milk pack","description":"haleeb","imageUrl":"milk.jpg","price":350.00,"category":null,"orderDetail":[]},{"id":8,"name":"oil","description":"olive oil ","imageUrl":"/resources/uploads/olive.png","price":670.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design ","imageUrl":"/static/uploads","price":34569.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design ","imageUrl":"/static/uploads","price":34569.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design ","imageUrl":"/static/uploads","price":34569.00,"category":null,"orderDetail":[{"id":263,"productlist":[{"id":10,"name":"Mobile","description":"awesome design, slim design
.
.
.and so on
我的实体正在关注
产品表
@ManyToMany(mappedBy = "productlist")
private List<OrderDetail> orderDetail =new ArrayList<OrderDetail>();
订单详情表
@ManyToMany
@JoinTable(
name="order_detail_productlist",
joinColumns=@JoinColumn(name="order_detail_id", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(name="productlist_id", referencedColumnName="id"))
private Set<Product> productlist = new HashSet<Product>();
我正在使用spring data jpa存储库来获取它们
List<Product> findAll();
注意:尚未订购哪些产品正常工作
答案 0 :(得分:0)
您需要所有日志以获取信息,这可能是由jackson
时的循环引起的。因此,您需要添加@JsonIgnoreProperties
。请参阅http://stackoverflow.com/questions/3325387
答案 1 :(得分:0)
使用jackson 2.0文档解决了我的问题
添加以下注释或OrderDetail表
@JsonBackReference
它打破循环并正确显示结果