0
Hello, I’m on a project and I need to do bidirectional relationship between two entities, the relationship is @OneToMany
@ManyToOne
, so far so good. But I wonder if there is any way to do it without using DTO?
@Entity
public class Answer extends BasicForum {
@ManyToOne
@JsonIgnore
private Question question;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "answer")
private List<CommentAnswer> commentList;
@Entity
public class Question extends BasicForum{
private String title;
private Integer views;
@OneToMany(fetch= FetchType.LAZY, cascade= CascadeType.ALL, mappedBy = "question")
private List<Answer> answerList;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "question")
private List<CommentQuestion> commentList;
I thank all of the community.
The relationship is already bidirectional, had some problem?
– Sidney
@Matheussilva the problem is Jsonignore, it cuts the bidirectionality because it ignores in json the attribute Question within Answer, if I remove it the relationship tends to infinity and a stack burst because a Question has a list of Answer, that each attribute on the list has a Question, which has a list of Answer.... and so it goes on to infinity.
– Felipe Paetzold