Java Hibernate json infinite recursion with self referencing class

后端 未结 2 721
攒了一身酷
攒了一身酷 2020-12-18 14:56

class employee:

@Entity
@Table(name = \"Employee\")
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = \         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 15:09

    I know that this question is old but just in case someone stumbles upon this.

    You've put the annotations in the wrong order. Here is my example:

    @Getter
    @Setter
    @NoArgsConstructor
    public class OutboundGoodsTypeDTO extends OutboundEntityDTO {
    
      @JsonManagedReference
      private OutboundGoodsTypeDTO parent;
    
      @JsonBackReference
      private Set goodsTypes;
    }
    

    From the documentation:

    @JsonManagedReference

    Annotation used to indicate that annotated property is part of two-way linkage between fields; and that its role is "parent" (or "forward") link.

    @JsonBackReference

    Annotation used to indicate that associated property is part of two-way linkage between fields; and that its role is "child" (or "back") link.

提交回复
热议问题