79772404

Date: 2025-09-23 09:04:42
Score: 0.5
Natty:
Report link

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;

}

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...

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @OneToMany
  • User mentioned (0): @OneToOne
  • User mentioned (0): @ManyToMany
  • User mentioned (0): @OneToMany
  • User mentioned (0): @OneToMany
  • Low reputation (1):
Posted by: LunaLissa