I'm using Lombok to remove boilerplate code. I'm attempting to print out an entity to the console but I'm getting a StackOverflowError. The entity has a bidirectional relationship with another entity, so I want to exclude this entity from the toString method.
My entity looks like this:
@Entity
@Data
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long fooId;
private String name;
@ManyToOne
@JoinColumn(name = "barId")
@EqualsAndHashCode.Exclude
@ToString.Exclude
private Bar bar;
}
This is my first time attempting to use @ToString.Exclude
and it doesn't appear to be behaving. Am I using it incorrectly? I just want to print out fooId
and name
when I call toString on the Foo object.
Edit
I'm familiar with alternate approaches to excluding or including fields from a top level @ToString
annotation. I'm attempting to avoid that. I just want to use @Data
at the class level, and annotate the fields that should be excluded.
Edit 2
Still replicating on a simplified class. Lombok version 1.18.8.