Skip to content
Advertisement

JPA Bidirectional relationship throws java.lang.StackOverflowError: null

i’m trying to relate two entities with JPA, when i run the project don’t throws me errors but when i request the method that get me the Voters of a Comunity Leader i get the next Exception:

JavaScript

I’ts like a loop, i don’t khow how to resolve this.

Here are my classes:

1)Leader Entity :

JavaScript

2)Voter Entity :

JavaScript

3)LeaderController :

JavaScript

I fill the tables with test data in import.sql.

Thanks in advance.

Advertisement

Answer

Hibernate OneToMany or JPA Bidirectional relationship throws java.lang.StackOverflowError: null is a Circular dependency issue that can originate from Lombok’s toString() autogenerated method if you use @Data complex annotation.

To exclude your circular dependency for a certain field or better still, you use @Getter and @Setter if you do not need the toString(). Well, when I had those issues above these solutions worked for me.

You may then use the @JsonIgnore on the particular attribute.

JavaScript
Advertisement