Spring Boot JPA - OneToMany relationship causes infinite loop

前端 未结 5 1267
走了就别回头了
走了就别回头了 2021-01-12 06:34

I have a two objects with simple @OneToMany relationship which looks as follows:

parent:

@Entity
public class ParentAccount {

  @Id
  @GeneratedValu         


        
5条回答
  •  有刺的猬
    2021-01-12 07:09

    Something like this does not work?

    @Entity
    public class Account {
    
        @Id
        @GeneratedValue
        private long id;
        private String name;
    
        @ManyToOne(cascade={CascadeType.ALL})
        @JoinColumn(name="manager_id")
        private Account manager;
    
        @OneToMany((fetch = FetchType.EAGER, mappedBy="manager")
        private Set linkedAccounts = new HashSet();
    
    }
    

提交回复
热议问题