> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/jpa-2-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/jpa-2-api/4.-api/repository-api-2.md).

# Repository와 API 분리2

**패키지의 목적과 용도에 따라 구분한다!**\
**OrderRepository : (핵심비즈니스)Order 엔티티 조회용⭐️**

**"query" : (핵심비즈니스X)화면이나 API에 의존적인 것들은 따로 패키지를 만들어서 처리한다!**\
**핵심 비즈니스를 처리하는 라이프 사이클과 화면/API 관련 라이프 사이클은 다르기 때문이다!**

**OrderQueryRepository, OrderDTO, OrderItemDTO 클래스 생성**\
OrderDTO만 만들어도 될텐데 Order에는 **일대다 관계의 컬렉션**이 있기 때문에 컬렉션은 **select절에서 new 연산자 바로 사용❌** 그렇기 때문에 **컬렉션 조회 쿼리작성은 따로 처리**해줘야 하기 때문에 **OrderItem 컬렉션에 대한 DTO도 따로 생성**.

![](https://690266786-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MevvVBGi1-NWjhdSHRP%2F-MfGJI8XQLEk_VudBiH3%2F-MfGJMEU_2c79wB0n6zr%2Fimage.png?alt=media\&token=c56684a2-9974-499d-ace6-46c134b98b75)
