0

I am getting StackOverflow recursion error when I run query in Postman . Here is the model classes :


@Entity
public class UserWallet {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    @NotNull
    private String userName;

    private String firstName;
    private String lastName;
    private String email;

    @Temporal(TemporalType.DATE)

    private Date createdDate;

    @OneToMany(mappedBy = "userAccount", fetch = FetchType.EAGER)

    private Set <Transaction> transactions = new HashSet<>();

Model class for Transaction:


@Entity
public class Transaction {

    @Id
    @GeneratedValue
    private Long id;

    private BigDecimal amount;

    private java.util.Date transactionDate;

    private Long  transactionReference;

    private String details;

    @ManyToOne

    private UserWallet userAccount;

When I run query on Postman it says :Could not write JSON: Infinite recursion (StackOverflowError); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.util.ArrayList[0]->com.Wallet.Model.UserWallet[\"transactions\"])".

wizdemonizer
  • 115
  • 4
  • 15
  • 1
    Looks like that the UserWallet is getting a transaction, which is getting an UserWallet which gets a transaction again, forming an infinite loop, try to debug the call and see if that is happening. – Cλstor Oct 15 '19 at 12:41

1 Answers1

0

if hibernate is throwing infinite loop stackflow error, Use @jsonIgnore property to stop the serialization.Then in deserialization JSON field will be ignored and no error will be thrown,this property is ignored and its value gets the default value of its type.

Follow the link for more :Ignore fields from Java object dynamically while sending as JSON from Spring MVC

Ayushi Keshri
  • 680
  • 7
  • 18