Spring Boot JPA - OneToMany relationship causes infinite loop
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.
Problem solved. I was using a custom @toString
method in the LinkedAccount which was referencing the ParentAccount. I had no idea that this could cause any problem and therefor I did not include the toString in my question.
Apparently, this was causing an infinite loop of lazy loading and removing this reference fixed the problem.