fetch join์ ์๋ฌ ๋ฌธ์ ๋ฌธ์์
๋๋ค!
๋ต๋ณ๋ด์ฉ ์๋์ ๊ฐ์ด ํ์ธํ์์ต๋๋ค!fetch join์ ์ฌ์ฉํ๋ ์ด์ ๋ ์ํฐํฐ ์ํ์์ ์ํฐํฐ ๊ทธ๋ํ๋ฅผ ์ฐธ์กฐํ๊ธฐ ์ํด์ ์ฌ์ฉํ๋ ๊ฒ์
๋๋ค. ๋ฐ๋ผ์ ๋น์ฐํ ์ํฐํฐ๊ฐ ์๋ DTO ์ํ๋ก ์กฐํํ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅํฉ๋๋ค.์ด ๊ฒฝ์ฐ fetch join์ ์ฌ์ฉํ์ง ๋ง์๊ณ , ๊ทธ๋ฅ ์์ํ join์ ์ฌ์ฉํ์๋ฉด ์ํ๋ ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค^^์ฐธ๊ณ ๋ก ๊ด๋ จ๋ ๋ถ๋ถ์ ํ์ฉ2ํธ์์ DTO๋ฅผ ์กฐํํ ๋ ์์ธํ ์ค๋ช
ํด๋๋ฆฌ๋ ์ฐธ๊ณ ํด์ฃผ์ธ์ :)์ ๋ถ๋ถ์ ๋ด์ฉ๋๋ก๋ผ๋ฉด, select > Qํด๋์ค ํ์ฉ๋ฅผ ํ์ฉํ๋, DTOํ์์ผ๋ก ๋ฐํjoin > Qํด๋์ค๋ง์ ํ์ฉํจ. ๋ ํํ์ ๊ธฐ์ค ์์ฒด๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ fetchjoin์ด ์๋๋ค๋ ์๋ฏธ์ธ์ง ๋ฌธ์๋๋ฆฝ๋๋ค! public List searchAllOrders(SearchRequestDto searchRequestDto) { return queryFactory .select(new QSearchResponseDto( account.name, product.seller, orderInfo.orderPrice, product.category ) ) .from(orderInfo) .join(orderInfo.product, product) .join(orderInfo.account, account) .where( nameEq(searchRequestDto.getAccountName()), sellerEq(searchRequestDto.getSeller()), orderPriceEq(searchRequestDto.getOrderPrice()), categoryEq(searchRequestDto.getCategory()) ) .fetch(); }