I have two entities, an entity \"movie\" and an entity \"Clip\" each clip belongs to one movie and a movie can have multiple clips.
My code looks like:
Basically JsonIgnore or JsonBackrefrencing will remove linking from one end.
To make proper linking as well as correct Json output, please follow below code snippet :-
@Entity
@Table(name="Movie")
public class Movie{
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@id")
@OneToMany(mappedBy="movie",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
private Set clips = new HashSet();
}
@Entity
@Table(name="Clip")
public class Clip{
@JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class, property="@id")
@ManyToOne
@JoinColumn(name="movie_id")
@JsonIgnore
private Movie movie;
}
refer below link for further details :- https://www.toptal.com/javascript/bidirectional-relationship-in-json
import com.fasterxml.jackson.annotation.ObjectIdGenerators;