Spring Boot JPA - OneToMany relationship causes infinite loop

前端 未结 5 1310
走了就别回头了
走了就别回头了 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:13

    As user1819111 told, @Data from Lombok is not compatible with @Entity and FetchType=LAZY. I had used Lombok.Data (@Data) and I was getting this error.

    As I don't want do create all get/set, I just put the Lombok @Setter and @Getter in your class and all will work fine.

    @Setter
    @Getter
    @Entity
    @Table(name = "file")
    @SequenceGenerator(name = "File_Sequence", allocationSize=1, sequenceName = "file_id_seq")
    public class MyClass{
        @Id
        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "File_Sequence")
        @Column(name = "id")
        private Long id;
    
        @Column(name = "name")
        private String name;
    
        @OneToMany(mappedBy = "file", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
        private Set details = new HashSet<>();
    }
    

提交回复
热议问题