Spring JPA bi-directional cannot evaluate toString

后端 未结 3 1369
南笙
南笙 2021-02-12 13:03

I have resolved JSON recursive loop with @JsonIdentityInfothrough to Baeldung\'s blog1 (Thanks)

But now, another error occurs :

Method threw         


        
相关标签:
3条回答
  • 2021-02-12 13:33

    Well, my guess is that Registration.toString() prints the string representation of each payment in the list, and since Payment.toString() includes the string representation of Registration, Registration.toString() is called again, which in turn calls Payment.toString() again, and so on.

    Try to return an empty string in Payment.toString() to see if the problem goes away.

    0 讨论(0)
  • 2021-02-12 13:42

    Remove toString method.

    In case you are using Lombok:

    Check you Entity/DAO class you might be using @Data annotation from lombok which by default includes getter and setters. Change it to @Getters and @Setter in case you need those and remove @Data annotation.

    0 讨论(0)
  • 2021-02-12 13:45

    in your Registration.toString() you are calling a Payment.toString() and on your Payment.toString() you are calling Registration.toString()

    You have created a loop in toString

      @Override
      public String toString() {
         return MoreObjects.toStringHelper(this)
            .add("payment", payment) //<----------- REMOVE THIS
            .toString();
      }
    

    or

       @Override
       public String toString() {
       return MoreObjects.toStringHelper(this)
            .add("registration", registration) //<----------- REMOVE THIS
            .toString();
       }
    

    Or better... remove both

    0 讨论(0)
提交回复
热议问题