I have 2 entities in spring: Category and Position with a OneToMany relation:
Category.java:
@Table(name = "category")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
int parentId;
String name;
@OneToMany(mappedBy = "category")
@JsonManagedReference(value = "referenceCallInCategory")
List<Position> positionList;
// getters and setters
Position.java:
@Entity
public class Position {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
int id;
String position;
String company;
String description;
@ManyToOne
// @JsonBackReference (value = "referenceCallInPosition")
@JsonIgnoreProperties({"parentId","name","positionList"})
Category category;
// getters and setters
When I make a post request for a position through postman I get the following warning in my terminal: WARN 15904 --- [nio-8080-exec-2] .c.j.MappingJackson2HttpMessageConverter : Failed to evaluate Jackson deserialization for type [[simple type, class positionsSite.positions.mode l.Position]]: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot handle managed/back reference 'referenceCallInCategory': no back reference property found from type [collection type; class java.util.List, contains [simple type, class positionsSite.positions.model.Position]]
The strange thing is when making a postrequest for a category the exact same warning occurs but after I make a postrequest for category, the postrequests for position work without a problem. Until I restart the application, then it fails again.
The reason I have @JsonIgnoreProperties instead of @JsonBackReference is that I need the Category.id when I make a get request for position. Given the warning no back reference property found I tried the @JsonBackReference as commented in the code, but this did not change anything.
Any help on how to solve this would be much appreciated