분류 전체보기
-
데이터베이스를 기반으로 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..
-
조회수 변경 시 발생하는 레이스 컨디션과 해결 방법운영 중인 서비스/Coconut. 2024. 2. 2. 13:59
게시판에 조회수를 요청이 들어오는대로 1씩 올려주다보면 정합성 이슈를 만날 수 있습니다. 레이스 컨디션이 발생하는 이유와 어떻게 해결하는지 적어보겠습니다. 1. 레이스 컨디션 발생 확인 현재 로직은 게시판 상세 내용을 get 요청하는 경우 view count를 1씩 올리는 형태로 작성되어있습니다. public PostResDto getPost(long postId) { Optional optPost = postRepository.findById(postId); Post post = optPost.orElseThrow(() -> new NotFoundException("[postId: " + postId + "] 게시글이 존재하지 않습니다")); post.setViewCount(post.getViewCou..
-
음식 배달 서비스 시스템문제풀이/데이터베이스 설계 2024. 2. 1. 23:51
테이블 설계 요구사항 : 음식 배달 서비스 시스템 음식 배달 서비스는 사용자들이 온라인으로 음식을 주문하고, 지역 레스토랑에서 배달을 받을 수 있는 서비스입니다. 이 시스템은 고객, 레스토랑, 주문, 주문 상세, 배달원 등 여러 엔터티를 포함합니다. 고객(Customers): 고객은 이름, 이메일, 주소, 가입일 등의 정보를 가집니다. 레스토랑(Restaurants): 각 레스토랑은 이름, 주소, 연락처, 평균 평점 등의 정보를 가집니다. 음식 메뉴(FoodItems): 음식 메뉴는 해당 레스토랑, 음식 이름, 가격, 설명 등의 정보를 포함합니다. 주문(Orders): 주문은 주문한 고객, 주문한 레스토랑, 주문 날짜, 총 가격, 배달 상태(처리 중, 배달 중, 배달 완료 등)를 포함합니다. 주문 상세(..
-
String으로 사용되던 데이터 enum으로 상수처리운영 중인 서비스/Coconut. 2024. 1. 30. 18:15
빠르게 만든다는 핑계로 String으로 받아서 처리하던 값들을 enum으로 변경하려고 합니다. 게시글 작성에서 사용되는 카테고리와 게시글 정렬기준이 되는 값들을 프론트엔드와 상의하여 정리하였습니다. 1. Setter를 사용해서 enum 할당 게시글 목록을 조회할 때 사용하는 DTO입니다. sortBy 항목을 String으로 받고 있는데 굉장히 위험한 느낌입니다. orderBy도 마찬가지입니다. 모두 enum을 사용해서 상수처리 해보겠습니다. @Data @ToString @Slf4j @NoArgsConstructor @AllArgsConstructor public class ListReqDto { @Schema(description = "페이지 (1부터 시작)", example = "1") @Min(v..
-
온라인 쇼핑몰 주문 관리 시스템문제풀이/데이터베이스 설계 2024. 1. 29. 17:27
테이블 설계 요구사항: 온라인 쇼핑몰 주문 관리 시스템 온라인 쇼핑몰에서 사용될 주문 관리 시스템을 위한 데이터베이스를 설계해야 합니다. 다음 요구사항을 충족해야 합니다: 고객(Customers): 고객은 이름, 이메일, 주소, 가입일을 가지고 있어야 합니다. 상품(Products): 상품은 이름, 가격, 재고 수량, 제공 업체 정보를 가지고 있어야 합니다. 주문(Orders): 주문은 주문한 고객, 주문 날짜, 배송 주소, 주문 상태(처리 중, 배송 중, 배송 완료, 취소됨 등)를 포함해야 합니다. 주문 상세(Order Details): 각 주문에는 하나 이상의 상품이 포함될 수 있습니다. 주문 상세는 주문된 상품, 수량, 그리고 각 상품에 대한 가격 정보를 포함해야 합니다. Step1) 최초 작성 주..
-
도서관 관리 시스템문제풀이/데이터베이스 설계 2024. 1. 26. 18:17
테이블 설계 요구사항: 도서관 관리 시스템 도서관 관리 시스템을 위한 데이터베이스를 설계해야 합니다. 다음 요구사항을 충족해야 합니다: 도서(Books): 각 도서는 제목, 저자, 출판사, 출판일, ISBN(국제 표준 도서 번호)을 가지고 있어야 합니다. 회원(Members): 회원은 이름, 이메일, 가입일, 그리고 회원 ID를 가지고 있어야 합니다. 대출 정보(Loans): 어떤 회원이 어떤 책을 대출했는지에 대한 정보가 필요합니다. 대출일, 반납 예정일, 실제 반납일을 포함해야 합니다. 벌금(Fines): 반납이 지연될 경우 회원은 벌금을 지불해야 합니다. 회원별 누적 벌금 정보가 필요합니다. 이제 이 요구사항을 바탕으로 테이블 구조(스키마)를 설계해보세요. 각 테이블의 필드, 필드의 타입, 그리고 ..
-
테스트를 쓰면서 만난 좋지 않은 Util 클래스와 의존성관리운영 중인 서비스/Coconut. 2024. 1. 25. 22:58
첫 번째 배포 주기에는 로그인 없이 게시판 하나를 만드는 걸 목표로 진행을 하고 있습니다. 그래서 로그인 구현 전까지 게시글 수정, 삭제를 관리하기 위해서 비밀번호를 사용하기로 결정하였습니다. 비밀번호를 디비에 넣기 전에 암호화를 위해서 간단하게 아래와 같이 클래스를 만들어보았습니다. public class SimpleEncrypt { public static boolean match(String rawString, String hashedString) { String hashedPassword = encrypt(rawString); return hashedString.equals(hashedPassword); } public static String encrypt(String rawString) { t..