I prefer to use many-to-one to prevent recursive and relational fetching issue. You don't need to manage fetch type... It's less effort and less error... and less Frustate...
@Entity
@Data
public class Content {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long contentId;
private String contentName;
@Column(columnDefinition = "TEXT")
private String synopsis;
@ManyToOne
@JoinColumn(name = "content_type_id")
private ContentType contentType;
@ManyToOne
@JoinColumn(name = "country_code")
private Country countryCode;
private String portraitUrl;
private String landscapeUrl;
private Boolean featured;
@Enumerated(EnumType.STRING)
private ContentApprovalStatus approvalStatus;
@CreationTimestamp
private LocalDateTime createTime;
@UpdateTimestamp
private LocalDateTime updateTime;
@Entity
@Data
public class ContentGenre {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long contentId;
@ManyToOne
@JoinColumn(name = "content_id")
private Content content;
@ManyToOne
@JoinColumn(name = "genre_id")
private Genre genre;
}
@Entity
@Data
public class ContentLanguage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long contentId;
@ManyToOne
@JoinColumn(name = "content_id")
private Content content;
@ManyToOne
@JoinColumn(name = "language_id")
private Language language;
}
You don't need @OneToMany contentCrews inside Content Entity, you have Content and Crew on ContentCrew, so delete it
@OneToMany(mappedBy = "content", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<ContentCrew> contentCrews;
You dont need @OneToMany contentCrew inside Crew Entity, you have ContentCrew table to handle it.
@OneToMany(mappedBy = "crew", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<ContentCrew> contentCrews;
So, you just need ContentCrews to manage content and crews. If you want to get content by crew or get crew by content, jut use ContentCrew table and delete fetchType.LAZY.
public class ContentCrew {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@JoinColumn(name = "content_id")
private Content content;
@JoinColumn(name = "crew_id")
private Crew crew;
private String role;
}
This is the easiest manage entity for you...