Skip to content

Commit 7903a20

Browse files
committed
[refactor/#83] 문제 조회 fetchjoin
1 parent d956372 commit 7903a20

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

src/main/generated/com/moplus/moplus_server/domain/problem/service/mapper/ChildProblemMapperImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
@Generated(
1313
value = "org.mapstruct.ap.MappingProcessor",
14-
date = "2025-03-03T17:28:35+0900",
14+
date = "2025-03-04T02:15:33+0900",
1515
comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.10 (JetBrains s.r.o.)"
1616
)
1717
@Component

src/main/generated/com/moplus/moplus_server/domain/problem/service/mapper/ProblemMapperImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
@Generated(
1717
value = "org.mapstruct.ap.MappingProcessor",
18-
date = "2025-03-03T17:28:35+0900",
18+
date = "2025-03-04T02:15:33+0900",
1919
comments = "version: 1.6.3, compiler: javac, environment: Java 17.0.10 (JetBrains s.r.o.)"
2020
)
2121
@Component

src/main/generated/com/moplus/moplus_server/domain/v0/TestResult/entity/QIncorrectProblem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class QIncorrectProblem extends EntityPathBase<IncorrectProblem> {
3737

3838
public final NumberPath<Long> practiceTestId = createNumber("practiceTestId", Long.class);
3939

40-
public final NumberPath<Long> problemId = createNumber("problemCustomId", Long.class);
40+
public final NumberPath<Long> problemId = createNumber("problemId", Long.class);
4141

4242
public final StringPath problemNumber = createString("problemNumber");
4343

src/main/generated/com/moplus/moplus_server/domain/v0/practiceTest/domain/QProblemImageForTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class QProblemImageForTest extends EntityPathBase<ProblemImageForTest> {
2525

2626
public final StringPath imageUrl = createString("imageUrl");
2727

28-
public final NumberPath<Long> problemId = createNumber("problemCustomId", Long.class);
28+
public final NumberPath<Long> problemId = createNumber("problemId", Long.class);
2929

3030
public QProblemImageForTest(String variable) {
3131
super(ProblemImageForTest.class, forVariable(variable));

src/main/java/com/moplus/moplus_server/domain/problem/domain/problem/Problem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class Problem extends BaseEntity {
7575

7676
private boolean isConfirmed;
7777

78-
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
78+
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
7979
@JoinColumn(name = "problem_id")
8080
@OrderColumn(name = "sequence")
8181
private List<ChildProblem> childProblems = new ArrayList<>();

src/main/java/com/moplus/moplus_server/domain/problem/repository/ProblemRepository.java

+14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemCustomId;
55
import com.moplus.moplus_server.global.error.exception.ErrorCode;
66
import com.moplus.moplus_server.global.error.exception.NotFoundException;
7+
import java.util.Optional;
78
import org.springframework.data.jpa.repository.JpaRepository;
9+
import org.springframework.data.jpa.repository.Query;
10+
import org.springframework.data.repository.query.Param;
811

912
public interface ProblemRepository extends JpaRepository<Problem, Long> {
1013

@@ -22,7 +25,18 @@ default void existsByProblemAdminIdElseThrow(ProblemCustomId problemCustomId) {
2225
}
2326
}
2427

28+
@Query("SELECT DISTINCT p FROM Problem p " +
29+
"LEFT JOIN FETCH p.childProblems c " +
30+
"LEFT JOIN FETCH p.conceptTagIds " +
31+
"LEFT JOIN FETCH c.conceptTagIds " +
32+
"WHERE p.id = :id")
33+
Optional<Problem> findByIdWithFetchJoin(@Param("id") Long id);
34+
2535
default Problem findByIdElseThrow(Long id) {
2636
return findById(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND));
2737
}
38+
39+
default Problem findByIdWithFetchJoinElseThrow(Long id) {
40+
return findByIdWithFetchJoin(id).orElseThrow(() -> new NotFoundException(ErrorCode.PROBLEM_NOT_FOUND));
41+
}
2842
}

src/main/java/com/moplus/moplus_server/domain/problem/service/ProblemGetService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ProblemGetService {
1515

1616
@Transactional(readOnly = true)
1717
public ProblemGetResponse getProblem(Long problemId) {
18-
Problem problem = problemRepository.findByIdElseThrow(problemId);
18+
Problem problem = problemRepository.findByIdWithFetchJoinElseThrow(problemId);
1919
return ProblemGetResponse.of(problem);
2020
}
2121
}

0 commit comments

Comments
 (0)