기존 설계에서 Test 엔티티의 역할
초기 설계에서는 Test 엔티티가 존재하여 StudentTest 및 ProblemSet과 연관을 맺고 있었다.
원래 설계 자체가 Test 엔티티를 먼저 생성을 한 후 Student 엔티티와 N:M 관계를 맺기위해 StudentTest 엔티티를 만들었다.
Test 엔티티의 주요 역할은 다음과 같습니다:
- 시험의 개념적 관리: 특정 시험을 식별하고, 관련된 문제(problem set)를 그룹화하는 역할
- 학생과 문제의 연결 고리: StudentTest와 ProblemSet이 Test를 참조하여 시험을 진행
- 시험 단위의 개념적 유지: 시험이라는 개념을 독립적인 엔티티로 유지하여, 여러 학생이 동일한 시험에 응시할 수 있도록 구성
- Test Entity
@Entity
@Table(name = "test")
public class Test {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "lecture_id", nullable = false)
private Lecture lecture; // 특정 강의와 연결
}
- StudentTest Entity
@Entity
@Table(name = "student_test")
public class StudentTest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "student_id", nullable = false)
private Student student;
@ManyToOne
@JoinColumn(name = "test_id", nullable = false)
private Test test; // 특정 시험을 참조
}
- ProblemSet Entity
@Entity
public class Problem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String content;
private String answer;
@Enumerated(EnumType.STRING)
private ProblemType problemType;
}
문제점 이후 해결방안 (Test 제거, StudentTest 와 ProblemSet 직접 연결)
- Test 엔티티는 중간 다리 역할만 수행 → 불필요한 엔티티
- StudentTest가 Test를 참조한 후, ProblemSet과 연결 → 쿼리 복잡성 증가
- 실제로 ProblemSet은 Test를 거치지 않고도 StudentTest와 직접 연결될 수 있음
- Test 엔티티 삭제
- StudentTest에 문제지(ProblemSet) 직접 연결
- ProblemSet을 StudentTest와 1:1 관계로 변경
→ 문제지는 하나의 StudentTest에서만 사용되도록 설계
'EduClass Project' 카테고리의 다른 글
[Project] 학생 시험 채점 기능 개선 - DTO 활용으로 확장성 높이기 (0) | 2025.03.07 |
---|---|
[Project] N:M 매핑에서 복합 키(Composite Key)를 사용할 때 주의할 점 (0) | 2025.03.05 |
[Project] (4) API 구현(@RequestParam vs @PathVariable) (0) | 2025.02.07 |
[Project] (3) 프로젝트 시작(MVC 패턴, 디렉토리 구조) (1) | 2025.02.05 |
[Project] (2) 프로젝트 시작(Entity 설계, 변수명) (1) | 2025.01.24 |