Skip to content
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

[4기 전선희] Mission 3 PR 제출합니다! #288

Open
wants to merge 2 commits into
base: funnysunny08-mission03
Choose a base branch
from

Conversation

funnysunny08
Copy link

📌 과제 설명

springboot-jpa mission 3 구현

👩‍💻 요구 사항과 구현 내용

  • 연관관계매핑(order, order_item, item의 연관관계 매핑 실습)

Copy link
Member

@JoosungKwon JoosungKwon left a comment

Choose a reason for hiding this comment

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

선희님 3번째 과제까지 고생하셨습니다~~ 👍👍 간단한 리뷰 남겼습니다! 참고해주세요~

p.s 연관 관계에 대한 다이어그램까지 있다면 좋을 것 같아요~~ 😄

@Column(nullable = false)
private String lastName;

@OneToMany(mappedBy = "customer", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
Copy link
Member

Choose a reason for hiding this comment

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

각 옵션에 대해 알고 계신가요~?

Comment on lines +21 to +23
customer.setId(1L);
customer.setFirstName("honggu");
customer.setLastName("Kang");
Copy link
Member

Choose a reason for hiding this comment

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

Setter가 어디서 선언된거죠..😂 Setter보다 생성자를 활용하면 좋을 것 같아요~


// Then
Customer entity = repository.findById(1L).get();
log.info("{} {}", entity.getLastName(), entity.getFirstName());
Copy link
Member

Choose a reason for hiding this comment

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

log를 남기기 보다 값을 검증해보면 좋을 것 같아요!

private Long id;

@Column(name = "memo", nullable = true)
@Setter
Copy link
Member

Choose a reason for hiding this comment

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

Setter 보다 의미있는 메서드를 사용하는게 좋다는 거 아시죠~?

@Column(name = "order_date_time", columnDefinition = "TIMESTAMP", nullable = false)
private LocalDateTime orderDateTime;

@ManyToOne(fetch = FetchType.EAGER)
Copy link
Member

Choose a reason for hiding this comment

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

FetchType에 대해 잘 알고 계신가요? EAGER로 하신 이유가 궁금합니다

private Customer customer;

@OneToMany(mappedBy = "order", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<OrderItem> orderItems;
Copy link
Member

Choose a reason for hiding this comment

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

기본 리스트를 가지고 있으면 좋을 것 같아요!

Comment on lines +34 to +44
setOrderItem(orderItem);
}

private void setOrderItem(OrderItem orderItem) {
if (Objects.nonNull(this.orderItem)) {
this.orderItem.getItems().remove(this);
}

this.orderItem = orderItem;
orderItem.getItems().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.

어떤 의도를 가지고 private으로 두고 생성자에서 추가하는 방식을 선택하셨는지 궁금합니다~

@Entity
@Table(name = "items")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Item {
Copy link
Member

Choose a reason for hiding this comment

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

Item을 재사용할 수 있나요?

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.

2 participants