I have a task and a user entity, with a one-to-many relationship. So in english a user can have multiple tasks, and a task belongs to a single user
public class User {
@Id
private Long id;
@OneToMany(mappedBy="task")
private Set<Task> tasks;
}
public class Task {
@Id
private Long id;
@ManyToOne
@JoinColumn(name="user_id", nullable=false)
@JsonIdentityInfo(generator= ObjectIdGenerators.PropertyGenerator.class, property="id")
@JsonIdentityReference(alwaysAsId=true)
@JsonProperty("user_id")
private User user;
private String name;
}
When i try to POST a task with
{
"name": "Test task",
"user_id": 1
}
i get the following:
Unresolved forward references for: ; nested exception is com.fasterxml.jackson.databind.deser.UnresolvedForwardReference
EDIT: Following this post and implementing an EntityIdResolver returns in this error:
Unable to locate persister: java.lang.Object; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unable to locate persister