Skip to content

Commit

Permalink
[BUG] 회원 탈퇴 API 오류 (#81)
Browse files Browse the repository at this point in the history
* feat: 양방향 연관관계 설정 (#80)

* feat: 연관관계 편의 메서드 추가 (#80)

* feat: JPA CASCADE 설정 (#80)

* feat: JPA orphanRemoval 설정 (#80)

* chore: dev 프로필 설정 변경 (#80)
  • Loading branch information
hyunmin0317 authored Oct 9, 2024
1 parent 204f18c commit df45584
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ public class Answer extends BaseEntity {
@JoinColumn(name = "question_id")
private Question question;

public void setMember(Member member) {
this.member = member;
member.getAnswers().add(this);
}

public void setQuestion(Question question) {
this.question = question;
question.setAnswer(this);
}

public void setData(Member member, Question question) {
this.member = member;
setMember(member);
setQuestion(question);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public class Question extends BaseEntity {
@JoinColumn(name = "member_id")
private Member member;

@OneToOne(mappedBy = "question", fetch = FetchType.LAZY)
@OneToOne(mappedBy = "question", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Answer answer;

public void setMember(Member member) {
this.member = member;
member.getQuestions().add(this);
}

public void setAnswer(Answer answer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.smunity.server.global.common.entity;

import com.smunity.server.domain.answer.entity.Answer;
import com.smunity.server.domain.course.entity.Course;
import com.smunity.server.domain.question.entity.Question;
import com.smunity.server.global.common.entity.enums.Category;
import com.smunity.server.global.common.entity.enums.MemberRole;
import com.smunity.server.global.common.entity.enums.SubDomain;
Expand Down Expand Up @@ -49,9 +51,15 @@ public class Member extends BaseEntity {
@JoinColumn(name = "department_id")
private Department department;

@OneToMany(mappedBy = "member")
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Course> courses = new ArrayList<>();

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Question> questions = new ArrayList<>();

@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<Answer> answers = new ArrayList<>();

public void setInfo(Year year, Department department, String encodePw) {
this.year = year;
this.department = department;
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ spring:
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver

data:
redis:
host: ${REDIS_URL}
port: ${REDIS_PORT}

jpa:
properties:
hibernate:
Expand Down

0 comments on commit df45584

Please sign in to comment.