강의

멘토링

커뮤니티

Inflearn Community Q&A

pci2676's profile image
pci2676

asked

Java ORM Standard JPA Programming - Basics

Value Type Collection

값 타입 컬렉션에서 일대다 매핑으로 바꾼 뒤!

Written on

·

261

0

수정을 하고 싶을 때, 값 타입 컬렉션 경우에는 

.remove()와 .add()를 사용하여 아래와 같이 했습니다.

findMember.getAddressHistory().remove(new AddressEntity("oldCity1", "street1", "10000"));
findMember.getAddressHistory().add(new AddressEntity("newCity1", "street1", "10000"));

그렇다면, AddressEntity를 사용하여 엔티티의 경우에는 아래와 같이 사용하면 되나요?

AddressEntity addressEntity = em.find(AddressEntity.class, 2L);
Address address = new Address("newCity1", "street1", "10000");
addressEntity.setAddress(address);

setAddress와 같이 커밋시점에 변경 감지로 수정을 할 수 있다고 생각했습니다.

javaJPA

Answer 1

0

yh님의 프로필 이미지
yh
Instructor

안녕하세요. Chan Chan님

생각하신 것 처럼 사용하셔도 문제가 있는 것은 아닙니다.

다만 이 경우 그러니까 컬렉션이 아닌 경우라면

예를 들어서 Member에서 AddressEntity를 사용하기 보다는 Address를 직접 사용하는 것이 더 나은 방향이라 생각합니다.

감사합니다.

pci2676님의 프로필 이미지
pci2676
Questioner

답변 감사합니다!!!

pci2676's profile image
pci2676

asked

Ask a question