Hibernate OneToMany java.lang.StackOverflowError

后端 未结 10 1036
傲寒
傲寒 2020-12-07 19:58

It\'s my first question here on stack, so please be gentle :D

I\'m trying to create hibernate OneToMany relationship. When I try to fetch some data from my DB, I\'m

10条回答
  •  余生分开走
    2020-12-07 20:56

    I had a very similar issue. I was using Lombok's @Data annotation on my model objects to auto-generate getters, setters, and other standard methods. I believe the toString() method generated by Lombok introduced a circular dependency between my Team and League objects. When I tried to get the Set teams from my League object, I got a java.lang.StackOverflowError because Spring was calling the toString method for logging purposes.

    I resolved this by getting rid of Lombok's toString() method. I replaced the @Data annotation with Lombok's @Getter and @Setter annotations. That way I still could benefit from free getters and setters without getting the toString() method.

提交回复
热议问题