소개
게시글
질문&답변
2021.09.09
복합키 식별관계 재질문입니다.
이것저것 해보다가 특정 부분을 수정했더니 테스트가 정상적으로 진행되는 부분이 있어서 답변하시는데 좀 더 수월하시지않을까 하고 추가 정보를 올립니다. 기존에는 엔티팅의 id 컬럼 명칭을 아래와 같이 했습니다. 변경전 public class LectureType { @Column(name = "lecture_type_category") @Id private String category; @Column(name = "lecture_type_level") @Id private String level; @Column(name = "lecture_type_name") private String name; @Column(name = "lecture_type_description") private String description; @Builder public LectureType(String category, String level, String name, String description) { this.category = category; this.level = level; this.name = name; this.description = description; }} public class ExamType { @Column(name = "exam_type_category") @Id private String category; @ManyToOne(fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn(name = "lecture_type_category", referencedColumnName = "lecture_type_category"), @JoinColumn(name = "lecture_type_level", referencedColumnName = "lecture_type_level") }) @Id private LectureType lectureType; @Column(name = "exam_type_name") private String name; @Builder public ExamType(String category, LectureType lectureType, String name) { this.category = category; this.lectureType = lectureType; this.name = name; }} 컬럼명칭을 변경했습니다. 변경후 public class LectureType { @Column(name = "lt_category") @Id private String category; @Column(name = "lt_level") @Id private String level; @Column(name = "lecture_type_name") private String name; @Column(name = "lecture_type_description") private String description; @Builder public LectureType(String category, String level, String name, String description) { this.category = category; this.level = level; this.name = name; this.description = description; }} public class ExamType { @Column(name = "exam_type_category") @Id private String category; @ManyToOne(fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn(name = "lt_category", referencedColumnName = "lt_category"), @JoinColumn(name = "lt_level", referencedColumnName = "lt_level") }) @Id private LectureType lectureType; @Column(name = "exam_type_name") private String name; @Builder public ExamType(String category, LectureType lectureType, String name) { this.category = category; this.lectureType = lectureType; this.name = name; }} 변경후에는 테스트가 정상적으로 통과했습니다.
- 0
- 2
- 655
고민있어요
2021.09.04 19:28
복합키 식별자 관계
- 0
- 1
- 187