I have a two objects with simple @OneToMany relationship which looks as follows:
parent:
@Entity
public class ParentAccount {
@Id
@GeneratedValu
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.