N+1 Problem
N+1 Problem
왜 발생할까?
N + 1 예시 코드
@Entity(name = "post")
data class Post (
@field:Id
@field:GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,
val title: String,
val content: String,
val author: String,
@field:OneToMany(mappedBy = "post", fetch = FetchType.LAZY)
val comments: List<Comment> = listOf()
)왜 문제가 될까?
해결 방법
🚨 fetchType.EAGER을 사용하면 안됨!!
FetchJoin 사용
BatchSize
EntityGraph 사용
그 외 방법들
결론
Referenec
Last updated




