▲ BoardRepositoryTest > SPRING_DATA_JPA

본문 바로가기

사이트 내 전체검색

뒤로가기 SPRING_DATA_JPA

▲ BoardRepositoryTest

페이지 정보

작성자 관리자 작성일 24-06-29 09:48 조회 73 댓글 0

본문

package web.repository;


import java.util.Optional;

import java.util.UUID;

import java.util.stream.IntStream;


import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.data.domain.Page;

import org.springframework.data.domain.PageRequest;

import org.springframework.data.domain.Pageable;

import org.springframework.data.domain.Sort;

import org.springframework.test.annotation.Commit;


import jakarta.transaction.Transactional;

import lombok.extern.log4j.Log4j2;

import web.domain.Board;

import web.domain.BoardImage;

import web.dto.BoardListReplyCountDTO;


@SpringBootTest

@Log4j2

public class BoardRepositoryTest {


@Autowired

private BoardRepository boardRepository;


@Autowired

private ReplyRepository replyRepository;


@Transactional

@Test

public void testSearchImageReplyCount() {

Pageable pageable = PageRequest.of(0, 10, Sort.by("bno").descending());


boardRepository.searchWithAll(null, null, pageable);

}

...

}






[콘솔 확인]
'N+1'로 실행되는 쿼리는 아래와 출력 구문과 같이 데이터베이스를 엄청나게 많이 사용하기 때문에 문제가 된다.
보안책은 @BatchSize를 이용하는 것이다.
Hibernate: 
    select
        b1_0.bno,
        b1_0.content,
        b1_0.moddate,
        b1_0.regdate,
        b1_0.title,
        b1_0.writer 
    from
        board b1_0 
    left join
        reply r1_0 
            on r1_0.board_bno=b1_0.bno 
    order by
        b1_0.bno desc 
    limit
        ?, ?
100
Hibernate: 
    select
        is1_0.board_bno,
        is1_0.uuid,
        is1_0.file_name,
        is1_0.ord 
    from
        board_image is1_0 
    where
        is1_0.board_bno=?
[]
-----------------------------
99
Hibernate: 
    select
        is1_0.board_bno,
        is1_0.uuid,
        is1_0.file_name,
        is1_0.ord 
    from
        board_image is1_0 
    where
        is1_0.board_bno=?
[BoardImage(uuid=b54a28fd-e615-4168-a094-bc6a5bf21821, fileName=99file1.jpg, ord=0), BoardImage(uuid=26639a76-30e0-4bdf-a87f-c9624380a7ca, fileName=99file2.jpg, ord=1)]
-----------------------------
98
Hibernate: 
    select
        is1_0.board_bno,
        is1_0.uuid,
        is1_0.file_name,
        is1_0.ord 
    from
        board_image is1_0 
    where
        is1_0.board_bno=?
[BoardImage(uuid=6223d77c-52dd-478e-95f2-c70b5d2c8382, fileName=98file2.jpg, ord=1), BoardImage(uuid=d2ef8cd5-d757-4cea-a2e3-0a3fe1c8fa4a, fileName=98file1.jpg, ord=0)]
-----------------------------

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기