Spring Boot JPA - OneToMany relationship causes infinite loop

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

    As the first answer suggests:

    Do not use Lombok's @Data annotation on @Entity classes.

    Reason: @Data generates hashcode(), equals() and toString() methods that use the generated getters. Using the getter means of course fetching new data even if the property was marked with FetchType=LAZY.

    Somewhere along the way hibernate tries to log the data with toString() and it crashes.

提交回复
热议问题