You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
안녕하세요.
Spring Boot + JPA 를 사용하면서 DDD 스타일로 도메인 모델과 엔티티(JPA) 모델을 분리하고 있습니다.
📌 상황
User↔Pet이OneToMany관계입니다.@OneToMany로 연결돼 있습니다.그대로
List<Pet>을 두기에는 N+1 / 연쇄 호출 문제 등 많은 이슈가 생깁니다.JPA Lazy Loading 을 사용할 수 없는 도메인 모델 구조라서
getPets()같은 메서드를 호출하면 Lazy 로딩이 자동 실행되는 방식이 아예 안 됩니다.→ 즉, 필요한 Pet 을 미리 로드하거나 별도의 서비스에서 찾아서 넣어줘야 합니다.
연관된 Pet 들을 도메인
User에 두면 Aggregate Root 책임이 과도해질 수도 있고,필요한 경우 Pet 조회를 위해 Repository 를 추가 호출해야 할 수도 있습니다.
또 List 을 그대로 두면 도메인 toString(), equals, hashCode 시 연쇄적으로 호출되는 문제가 자주 발생합니다.
💭 질문
✅ 그래서 여러분은 이런 구조에서 보통 어떻게 설계하시나요?
User도메인에 Pet 의 ID 만 두는 방식 (List<Long> petIds)?User.getPets()호출 시 따로 조회?여러분의 경험과 설계 사례를 듣고 싶습니다 🙌
Beta Was this translation helpful? Give feedback.
All reactions