Skip to content

JPA를 사용하여 네이버 예약 시스템 구현#21

Open
YooJisu826 wants to merge 1 commit intoLandvibeDev:YooJisu826from
YooJisu826:OT
Open

JPA를 사용하여 네이버 예약 시스템 구현#21
YooJisu826 wants to merge 1 commit intoLandvibeDev:YooJisu826from
YooJisu826:OT

Conversation

@YooJisu826
Copy link
Collaborator

@YooJisu826 YooJisu826 commented Aug 26, 2022

요약

3주차에 구현했던 네이버 예약 시스템에서 데이터를 메모리에 저장하는 것이 아닌, JPA를 사용하는 방법으로 변경하였습니다.
대부분의 변경점은 Entity, Repository, Service에 있습니다.

  • Entity : @entity, @table 등의 어노테이션 추가
  • Repository : JpaRepository를 상속받는 interface로 변경
  • Service : JPA 형식에 맞추어 함수 변경

어려웠던 점

JPA의 findAll()을 사용하여 각각 Entity List를 받아오려고 할 때 StackOverflowError가 발생했었습니다.
이유는 Entity를 작성할 때 양방향 맵핑을 했기 때문에 ToString()이라는 함수가 양쪽 Entity에서 반복되며 무한루프가 생긴 것이었습니다. 한 쪽 Entity에 @JsonIgnore이라는 어노테이션을 추가해주었더니 해결 되었습니다.

코드리뷰 받고 싶은 점

ProRepository에서 제가 별도로 @query를 이용하여 함수를 만들었는데, 이런 식으로 JPA와 Mybatis를 혼용해도 되는 것인지 궁금합니다.
각각 Controller와 Service에서 부족하게 작성된 부분이 없는 지 봐주셨으면 좋겠습니다!

@ResponseBody
public CategoryResponse create(@RequestBody CategoryRequest request) {
Long id = service.create(request);
Long id = service.create(request);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘했는데 전반적으로 네이밍을 조금만 더 신경쓰면 좋을거 같아
우선 그냥 service라 던지 혹인 categoryRepository를 cateRepository라 쓰는 것과 같이 줄여쓰는게, 혼자 개발을 할때는 헷갈리지 않을 수 있어도 협업을 하거나 다른 누군가가 보기에는 가독성이 좋지 않다고 나는 생각해
그래서 웬만하면 네이밍에 있어서 줄임말은 쓰지 않는게좋다고 생각합니당


@Entity
@Getter
@Setter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔티티를 설정함에 있어서 setter의 사용은 지양하는 편이 좋습니다
setter를 설정하게 되면 public으로 설정되기 때문에 어디서든 수정이 일어날 수있고 일관성을 유지하기 어려울 수 있고 어떤 기능인지 정확히 인지하기 어려울 수 있습니당
그래서 setter 보다는 직접 알아보기 좋은 네이밍을 통해 함수를 만들어 수정 기능을 넣어주는 것이 좋습니다~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants