SpringBoot Hibernate. Unable to GET findAll and findById in Postman, Swager, api link for OneToMany, ManyToOne relationship

Viewed 21

I'm unable to get response in Postman. It becomes an infinite loop I think. The models are: dish, category. One category had multiple dishes. enter image description here

Before add Dish (id, category), it behave normal like this enter image description here Here is the Dish and Category model enter image description here enter image description here Here is one of the Controller enter image description here The post dish working great, but the search is not. Anyone know how to solve it? (The db I use is Postgres)

Edit: I solved it. Using @JsonBackReference and @JsonManageReference

1 Answers

Your Dish & Category are related entities.

Try having @JsonIgnore annotation in your Dish class for Category field or the other way around.

Also, always use a DTO instead of returning the actual DB object in the Rest-call.

Related