I'm new in Spring Boot JPA
I have questions in JPA Entity mappings.
there is 4 tables in my MySql DB
SPACE, PROJECT, ISSUE, MEMBER
SPACE is Big Project which contains multiple PROJECT.
PROJECT contains multiple ISSUE.
and MEMBER can join only 1 SPACE and multiple PROJECT which MEMBER belongs to SPACE. MEMBER can write multiple ISSUE
in this situation, my ERD model is correct?
and please check my jpa mappings. If there's anything wrong, please point it out.
SPACE
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "space_no")
private Long spaceNo;
@NotEmpty
@Column(name = "space_name", unique=true, length = 100)
private String spaceName;
/** 1:N relation */
@OneToMany(mappedBy = "smsSpace")
private List<PmsProject> pmsProjects = new ArrayList<>();
PROJECT
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "project_no")
private Long projectNo;
@Column(name ="space_no")
private Long spaceNo;
@Column(name = "project_name", length = 100)
private String projectName;
/** 1:N relation */
@OneToMany(mappedBy = "pmsProject")
private List<ImsIssue> imsIssues = new ArrayList<>();
@OneToMany(mappedBy = "pmsProject")
private List<PmsProjectMember> projectMembers = new ArrayList<>();
/** N:1 relation */
@ManyToOne
@JoinColumn(name = "space_no", referencedColumnName = "space_no", insertable = false, updatable = false)
private SmsSpace smsSpace;
MEMBER
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "member_no")
private Long memberNo;
@Column(name = "mail_address", unique=true, length = 100)
private String mailAddress;
@Column(name = "name", length = 100)
private String name;
@Column(name = "keyword", length = 1000)
private String keyword;
@Column(name = "image", length = 1000)
private String image;
@Column(name = "password", length = 1000)
private String password;
@Column(name = "user_id", length = 50)
private String userId;
@Enumerated(EnumType.STRING)
private MemberRole role;
public void encodingPassword(String password) {
this.password = password;
}
/** 1:N realtion */
@OneToMany(mappedBy = "mmsMember")
private List<PmsProjectMember> projectMembers = new ArrayList<>();
ISSUE
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "issue_no")
private Long issueNo;
@Column(name ="project_no")
private Long projectNo;
@Column(name = "issue_name", length = 1000)
private String issueName;
@Column(name = "priority")
private Long priority;
@Column(name = "status", length = 20)
private String status;
@Column(name = "summary", length = 100)
private String summary;
@Column(name = "is_overdue")
private Long isOverdue;
@Column(name = "issue_type_cd")
private String issueTypeCd;
/** N:1 relation */
@ManyToOne
@JoinColumn(name = "project_no", referencedColumnName = "project_no", insertable = false, updatable = false)
private PmsProject pmsProject;
PROJECTMEMBER
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "group_no")
private Long groupNo;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "member_no")
private MmsMember mmsMember;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "project_no")
private PmsProject pmsProject;
I've been thinking about it for days, but I can't solve it because I lack knowledge. Please help me.