Skip to content

[4기 황창현, 이현호] JPA Mission 3 - 도메인 연관관계 매핑 실습 #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: 창현,현호-mission2
Choose a base branch
from

Conversation

Hchanghyeon
Copy link
Member

🥇 요구 사항 및 구현 내용

미션3

  • 연관 관계 매핑 실습

    • Customer와 Order의 일대다의 연관관계 매핑(양방향)
    • Order와 Customer의 다대일의 연관관계 매핑(양방향)
    • OrderItem과 Order의 다대일의 연관관계 매핑
    • OrderItem과 Item의 다대일의 연관관계 매핑
  • 연관 관계 테스트 코드 작성

    • 고객을 통해 주문 리스트를 조회할 수 있다.
    • 주문에서 고객을 조회할 수 있다.
    • 주문 아이템에서 주문을 조회할 수 있다.
    • 주문 아이템에서 아이템을 조회할 수 있다.

}

this.customer = customer;
customer.getOrders().add(this);
Copy link
Member

Choose a reason for hiding this comment

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

이 부분도 위쪽 리뷰를 참고하여 addOrder메소드를 만들어 정리해주세요!

Choose a reason for hiding this comment

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

넵 add 메서드도 적용했습니다~!

적용 커밋: e3a73f6

this.customer = customer;
customer.getOrders().add(this);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

이쪽 부분에도 OrderItem연관관계 편의 메소드에서 사용할 add,remove 메소드를 만들 수 있을 것 같아요!

Choose a reason for hiding this comment

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

Order역시 OrderItem과의 연관 관계는 단방향이라서 편의 메서드를 만들지 않았습니다.

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "item_id", referencedColumnName = "id")
private Item item;

Copy link
Member

Choose a reason for hiding this comment

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

Order, Item 클래스의 연관관계 편의 메소드를 만들어주세요!

Choose a reason for hiding this comment

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

단방향이라서 편의 메서드는 만들 수 없었습니다.

private String name;
private Integer price;
private Integer stockQuantity;

Copy link
Member

Choose a reason for hiding this comment

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

Order 클래스의 리뷰를 참고하여 연관관계 편의 메소드에서 사용할 add,remove 메소드를 만들수 있을 것 같아요!

Choose a reason for hiding this comment

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

Item의 경우 단방향 연관관계로 매핑되어 있어서 편의 메서드를 쓸 수 없다고 생각했습니다!

@jay-so
Copy link
Member

jay-so commented Aug 2, 2023

창현님, 현호님 수고하셨습니다! 😀😀
리뷰를 남겼습니다! 서로 피드를 주고 받으면서 의논했으면 좋겠습니다! 화이팅!!

Copy link
Member

@kylekim2123 kylekim2123 left a comment

Choose a reason for hiding this comment

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

다른 사항에 대해서는 재훈님이 잘 말씀해주신 것 같아서, 저는 간단하게 리뷰했습니다.
고생 많으셨어요!

class AssociationTest {

@Autowired
CustomerRepository customerRepository;
Copy link
Member

Choose a reason for hiding this comment

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

필드 사이에 한칸 씩 띄우면 가독성이 더 좋아질 것 같아요!

Choose a reason for hiding this comment

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

오 붙어있는 부분을 놓쳤네요. 적용했습니다~

적용 커밋: c6668a7

Customer savedCustomer = customerRepository.save(customer);
Order savedOrder = orderRepository.save(order);
Item savedItem = itemRepository.save(item);
OrderItem savedOrderItem = orderItemRepository.save(orderItem);
Copy link
Member

Choose a reason for hiding this comment

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

전체적으로 조회에 대한 테스트인데, 메서드 별로 계속 given을 위해서 생성이 이루어지는 것 같습니다.
이를 매번 메서드에서 진행하지 않고, BeforeAll을 이용해서 한번만 필요한 customer, order, item, orderItem 을 저장해놓고
테스트 메서드에서는 조회만 진행해보면 어떨까요?

Choose a reason for hiding this comment

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

공유할 수 있는 given자원에 대해 @transactional, @beforeeach를 통해 초기화 할 수 있도록 처리했습니다. 테스트 코드가 훨씬 간결해진 것 같네요!

적용 커밋: e136bc8

Copy link

@charlesuu charlesuu left a comment

Choose a reason for hiding this comment

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

리뷰 반영했습니다~!! 확인 해주시면 너무 감사하겠습니다.

private String name;
private Integer price;
private Integer stockQuantity;

Choose a reason for hiding this comment

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

Item의 경우 단방향 연관관계로 매핑되어 있어서 편의 메서드를 쓸 수 없다고 생각했습니다!

this.customer = customer;
customer.getOrders().add(this);
}
}

Choose a reason for hiding this comment

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

Order역시 OrderItem과의 연관 관계는 단방향이라서 편의 메서드를 만들지 않았습니다.

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "item_id", referencedColumnName = "id")
private Item item;

Choose a reason for hiding this comment

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

단방향이라서 편의 메서드는 만들 수 없었습니다.

class AssociationTest {

@Autowired
CustomerRepository customerRepository;

Choose a reason for hiding this comment

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

오 붙어있는 부분을 놓쳤네요. 적용했습니다~

적용 커밋: c6668a7

Customer savedCustomer = customerRepository.save(customer);
Order savedOrder = orderRepository.save(order);
Item savedItem = itemRepository.save(item);
OrderItem savedOrderItem = orderItemRepository.save(orderItem);

Choose a reason for hiding this comment

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

공유할 수 있는 given자원에 대해 @transactional, @beforeeach를 통해 초기화 할 수 있도록 처리했습니다. 테스트 코드가 훨씬 간결해진 것 같네요!

적용 커밋: e136bc8

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

Successfully merging this pull request may close these issues.

4 participants