SpringBoot + JPA 조인테이블 직접 설정 및 정렬 컬럼 추가
2023. 6. 28. 08:14ㆍ웹개발/JPA
728x90
// 강좌 와 시리즈 조인 테이블
@Data
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class LectureSeriesLecture{
@Id
private Long id;
@ManyToOne
@JoinColumn(name="lectureSeriesId")
private LectureSeries lectureSeries;
@ManyToOne
@JoinColumn(name="lectureId")
private Lecture lecture;
private Long orderNum;
}
위 테이블은 생성되는 조인테이블을 대체할 Entity 이다
// 강좌 시리즈 테이블
@Data
@Entity
@EqualsAndHashCode(of = "id")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class LectureSeries {
@Id
private Long id;
private String seriesName; // 시리즈 명
@OneToOne
private Account creater; // 작성자
@CreationTimestamp
@Column(updatable=false)
private LocalDateTime createAt;
@OneToOne
private Account updater; // 수정자
@UpdateTimestamp
private LocalDateTime updateAt;
@Builder.Default
private boolean deleteYn = false; // 삭제여부
@OneToMany(mappedBy = "lectureSeries")
@OrderBy(value = "orderNum")
private List<LectureSeriesLecture> lectureSerieslecture = new ArrayList<LectureSeriesLecture>();
}
위 테이블은 강좌의 시리즈 묶음 테이블이다.
// 강좌 테이블
@Data
@Entity
@EqualsAndHashCode(of = "id")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Lecture {
@Id
private Long id;
private String lectureName; // 제목
@OneToOne
private Account creater; // 작성자
@CreationTimestamp
@Column(updatable=false)
private LocalDateTime createAt; // 작성일자
@OneToOne
private Account updater; // 수정자
@UpdateTimestamp
private LocalDateTime updateAt;
@Builder.Default
private int hits = 0; // 조회수
@Builder.Default
private boolean deleteYn = false; // 삭제여부
@OneToMany(mappedBy = "practiceLecture")
private List<LectureSeriesLecture> lectureSerieslecture = new ArrayList<LectureSeriesLecture>();
}
위 테이블은 강좌 테이블이다.
728x90
반응형
'웹개발 > JPA' 카테고리의 다른 글
Spring Boot + JPA 작성일자 자동 수정 방지 (0) | 2023.06.29 |
---|