I've seen this problem pop up everywhere, and while i followed their solutions and it fixed my problem, i don't really understand what is happening. My Entities:
@Entity
public class ItemInOrder {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Long id;
@ManyToOne
Bill bill;
String comment;
}
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@id")
public class Bill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
@OneToOne
Table table;
@OneToMany(mappedBy = "bill")
List<ItemInOrder> itemi_vo_naracka = new ArrayList<>();
}
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@id")
public class Table {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
@OneToOne
Bill order_na_ovaa_masa;
}
My error comes when i call a basic JPA repository method to find all the ItemsInOrder:
return itemInOrderService.getAllItemsInOrder();
The exception says that the infinite loop is happening between Table and Bill:
Infinite recursion (StackOverflowError) (through reference chain: bla.bla.domain.Bill["table"]->bla.bla.domain.Table["order_na_ovaa_masa"]-> and so and so on..
So can someone explain to me what was happening before i added the @JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@id") above my entites, and what is happening after that.
I've read a few explanations but i don't really understand whats happening with all that serialization and deseralization. If the explanation is too long, a guide or link to a post where it is explained nicely would also do(for a complete beginner in all of this). Thanks!