I have problem with hibernate and JSON, when i use many to many for the same class, i get recursion
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.Set;
import java.util.UUID;
@Entity
public class AssistantGraphVertex {
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private UUID uuid;
@ManyToOne
private AssistantGraphs assistantGraphs;
private String name;
private String description;
@ManyToMany(cascade = {CascadeType.ALL})
@JoinTable(name = "assistant_graph_edge",
joinColumns = { @JoinColumn(name = "parent_uuid") },
inverseJoinColumns = { @JoinColumn(name = "child_uuid") }
)
private Set<AssistantGraphVertex> parents;
@ManyToMany(mappedBy = "parents")
private Set<AssistantGraphVertex> children;
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public AssistantGraphs getAssistantGraphs() {
return assistantGraphs;
}
public void setAssistantGraphs(AssistantGraphs assistantGraphs) {
this.assistantGraphs = assistantGraphs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<AssistantGraphVertex> getChildren() {
return children;
}
public void setChildren(Set<AssistantGraphVertex> children) {
this.children = children;
}
public Set<AssistantGraphVertex> getParents() {
return parents;
}
public void setParents(Set<AssistantGraphVertex> parents) {
this.parents = parents;
}
}
Problem look like this:
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Infinite recursion (StackOverflowError);
I would like to receive information only for one class about its parents and children, but for the next nested class, I do not need this information, how can this be better achieved?