Skip to content

Commit

Permalink
Merge pull request #137 from Media-XI/ARTDEV-156-be-연관-객체-조회-시-n-1-문제-해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoon9901 authored Mar 4, 2024
2 parents 068d08e + c01f691 commit c545a5d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Where;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -66,14 +67,17 @@ public class Magazine {
private MagazineCategory category;

@Builder.Default
@BatchSize(size = 25)
@OneToMany(mappedBy = "magazine", cascade = CascadeType.ALL)
private List<MagazineComment> magazineComments = new ArrayList<>();

@Builder.Default
@BatchSize(size = 25)
@OneToMany(mappedBy = "magazine", cascade = CascadeType.ALL)
private List<MagazineLike> magazineLikes = new ArrayList<>();

@Builder.Default
@BatchSize(size = 25)
@OneToMany(mappedBy = "magazine", cascade = CascadeType.ALL)
private List<MagazineMedia> magazineMedias = new ArrayList<>();

Check warning on line 82 in src/main/java/com/example/codebase/domain/magazine/entity/Magazine.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Mismatched query and update of collection

Contents of collection `magazineMedias` are updated, but never queried

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Where;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class MagazineComment {
private MagazineComment parentComment;

@Builder.Default
@BatchSize(size = 10) // TODO : 배치 사이즈를 부모 댓글 개수에 따라 조절
@OneToMany(mappedBy = "parentComment", fetch = FetchType.LAZY)
private List<MagazineComment> childComments = new ArrayList<>();

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ spring:
# show_sql: true
# format_sql: true
enable_lazy_load_no_trans: true # LAZY 로드를 default로 설정
default_batch_fetch_size: 30 # TODO : 상황에 맞게 조절

# # Flyway 사용으로 초기화 주석
# defer-datasource-initialization: true
Expand Down

0 comments on commit c545a5d

Please sign in to comment.