Infinite Recursion with Jackson JSON and Hibernate JPA issue

前端 未结 25 3177
你的背包
你的背包 2020-11-21 07:31

When trying to convert a JPA object that has a bi-directional association into JSON, I keep getting

org.codehaus.jackson.map.JsonMappingException: Infinite          


        
25条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 07:36

    I have the same problem after doing more analysis i came to know that, we can get mapped entity also by just keeping @JsonBackReference at OneToMany annotation

    @Entity
    @Table(name = "ta_trainee", uniqueConstraints = {@UniqueConstraint(columnNames = {"id"})})
    public class Trainee extends BusinessObject {
    
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE)
    @Column(name = "id", nullable = false)
    private Integer id;
    
    @Column(name = "name", nullable = true)
    private String name;
    
    @Column(name = "surname", nullable = true)
    private String surname;
    
    @OneToMany(mappedBy = "trainee", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @Column(nullable = true)
    @JsonBackReference
    private Set bodyStats;
    

提交回复
热议问题