프레임워크/Spring Boot
-
N + 1 정복하기 <5. Entity Graph>프레임워크/Spring Boot 2024. 2. 21. 13:27
시리즈1. https://iwsaitw.tistory.com/entry/N-1-정복하기 시리즈2. https://iwsaitw.tistory.com/entry/N-1-정복하기-2-FetchTypeEAGER 시리즈3. https://iwsaitw.tistory.com/entry/N-1-정복하기-3-Fetch-Join 시리즈4. https://iwsaitw.tistory.com/entry/N-1-정복하기-4-BatchSize (소스코드: https://github.com/blog-example/-JPA-N_Plus_1) ORM을 사용하면 만나는 흔한 이슈 중 하나인 N + 1 ! 명확하게 설명할 수 있을 정도로 머리속에 집어넣어보겠습니다. 이번 글에서는 Entity Graph를 활용해서 N + 1을 해결하는..
-
N + 1 정복하기 <4. @BatchSize>프레임워크/Spring Boot 2024. 2. 21. 03:40
시리즈1. https://iwsaitw.tistory.com/entry/N-1-정복하기 시리즈2. https://iwsaitw.tistory.com/entry/N-1-정복하기-2-FetchTypeEAGER 시리즈3. https://iwsaitw.tistory.com/entry/N-1-정복하기-3-Fetch-Join (소스코드: https://github.com/blog-example/-JPA-N_Plus_1) ORM을 사용하면 만나는 흔한 이슈 중 하나인 N + 1 ! 명확하게 설명할 수 있을 정도로 머리속에 집어넣어보겠습니다. 이번 글에서는 @BatchSize를 활용해서 N + 1을 해결하는 과정을 살펴보겠습니다. 이글은 3번 글에서 이어집니다. 3번 글을 보고 오시면 이해에 도움이 될 것 같습니다! ..
-
N + 1 정복하기 <3. Fetch Join>프레임워크/Spring Boot 2024. 2. 21. 02:57
시리즈1. https://iwsaitw.tistory.com/entry/N-1-정복하기 시리즈2. https://iwsaitw.tistory.com/entry/N-1-정복하기-2-FetchTypeEAGER (소스코드: https://github.com/blog-example/-JPA-N_Plus_1) ORM을 사용하면 만나는 흔한 이슈 중 하나인 N + 1 ! 명확하게 설명할 수 있을 정도로 머리속에 집어넣어보겠습니다. 이번 글에서는 fetch join을 활용해서 N + 1을 해결하는 과정을 살펴보겠습니다. 1. JPQL? Fetch Join? Fetch Join 을 이야기 하기에 앞서서 JPQL을 먼저 이야기할 필요가 있습니다. gpt가 뭐라고 정의하는지 한 번 보겠습니다. JPQL은 개발자가 원하는 ..
-
N + 1 정복하기 <2. FetchType.EAGER>프레임워크/Spring Boot 2024. 2. 20. 18:09
(소스코드: https://github.com/blog-example/-JPA-N_Plus_1) ORM을 사용하면 만나는 흔한 이슈 중 하나인 N + 1 ! 명확하게 설명할 수 있을 정도로 머리속에 집어넣어보겠습니다. 지난글에서 N + 1이 무엇이고 왜 발생하고 어떤 코드에서 발생하는지 살펴보았습니다. 이번 글에서는 FetchType.EAGER와 N + 1의 관계에 대해서 살펴보겠습니다. [글의 진행] 1. FetchType.EAGER 적용하기 2. FetchType.EAGER 공식문서 확인하기 3. FetchType.EAGER 실행확인하기 4. FetchType.EAGER의 또 다른 동작 지난 글에서 연관관계가 있는 엔티티 로딩시 성능 최적화를 위해서 FetchType.LAZY를 사용하면서 N + 1 ..
-
N + 1 정복하기 <1. N + 1?>프레임워크/Spring Boot 2024. 2. 20. 16:13
(소스코드: https://github.com/blog-example/-JPA-N_Plus_1) ORM을 사용하면 만나는 흔한 이슈 중 하나인 N + 1 ! 명확하게 설명할 수 있을 정도로 머리속에 집어넣어보겠습니다. 이번글에서는 N + 1이 무엇이고 왜 발생하고 어떤 코드에서 발생하는지 살펴보겠습니다. 1. N + 1이 무엇? 2. 프로젝트 세팅하기 3. N + 1 왜 발생하는가? 1. N + 1 이 무엇? gpt는 n + 1 이슈를 무엇이라고 정의하는지 살펴보겠습니다. 명쾌하게 잘 정리해준 것 같습니다! 면접 때 질문을 받으면 이 정도 내용으로 답변을 하면 좋겠다는 생각이 듭니다. # 데이터베이스 쿼리 최적화 이슈 # 한 번의 쿼리로 N개의 엔티티를 가져오지만 해당 엔티티에 접근할 때 추가로 N번의 ..
-
데이터베이스를 기반으로 JPA의 연관관계 살펴보기 <1>프레임워크/Spring Boot 2024. 2. 6. 20:10
소스코드: https://github.com/blog-example/-JPA-_relationship_mapping 이번에는 아티스트를 새로 등록하는 시나리오를 진행하면서 관련된 Entity 간의 연관관계를 맺는 법을 살펴보겠습니다. 0. 기본 시나리오 생성 우선 연관관계를 생각하지 않고 데이터베이스 레벨에서 테이블을 생성하고, JPA에서 Entity를 만들어보겠습니다. 아티스트는 솔로가수 혹은 아이돌 그룹을 생각해주시면 됩니다. 멤버는 솔로일 경우에 솔로 자신, 그룹일 경우 그룹의 멤버입니다. 연관 관계가 없는 상태의 아티스트와 멤버 ERD 입니다. 이를 표현하는 SQL을 사용해서 데이터베이스에 테이블을 생성해보겠습니다. CREATE TABLE IF NOT EXISTS artists( artist_id..
-
Entity의 Id 생성 전략에 따른 EntityManager의 persist 동작 확인프레임워크/Spring Boot 2024. 2. 6. 19:28
소스코드: https://github.com/blog-example/-JPA-_persist_with_how_to_generate_id (예제에서는 Spring boot web, jpa, lombok, connectorj를 의존성으로 사용하고 있습니다.) EntityManager의 persist의 동작이 예상하던 것과 다르게 작동하는 경우를 만나서 검증을 해보았습니다. 예제 사용될 간단한 Entity를 소개합니다. import jakarta.persistence.*; import lombok.Getter; @Getter @Entity @Table(name = "artists") public class Artist { @GeneratedValue(strategy = GenerationType.IDENTIT..
-
Spring boot 2.7.18에서 swagger 설정하기 <2>프레임워크/Spring Boot 2024. 1. 23. 02:21
프로젝트를 함께 만들고 있는 프론트엔드 개발자들과 효율적인 커뮤니케이션을 위해서 스웨거를 사용하려고 합니다. 적용하면 만난 이런 저런 이슈 사항들을 기록해보았습니다. 프로젝트 버전 spring boot: 2.7.18 springdoc-openapi-ui: 1.7.0 1. 프로젝트 코드에 작성 어노테이션을 사용해서 컨트롤러의 메소드와 관련된 dto들에 명세를 추가해주면 web에서 확인이 가능합니다. api 명세 작성 @Operation(summary = "게시글 생성", description = "제목, 내용, 작성자, 카테고리를 포함하는 게시글을 작성합니다.") @ApiResponses(value = { @ApiResponse(responseCode = "201", description = "게시물 생성..