무료
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결JPA & Spring Data JPA 기초
git 링크 안들어가져요 404에러
https://github.com/madvirus/jpa-basic/jpa-01git링크가 들어가면 404가 뜹니다
- 해결됨JPA & Spring Data JPA 기초
JoinColumn 질문
참조키 예시에서@JoinColumn에서 name속성으로 지정하기 전에 "user_email"@Columnprivate String user_email; 이렇게 먼저 선언되어 있어야 되는거 아닌가요??
- 미해결JPA & Spring Data JPA 기초
1:N 매핑과 해당 방식 차이가 뭔가요?
1:N 매핑과 해당 방식 차이가 뭔가요?
- 해결됨JPA & Spring Data JPA 기초
10강 3:37 질문
@Access는 JPA가 엔티티 데이터에 접근하는 방식을 지정하는 에너테이션으로 알고 있습니다.그런데 사진에서 @Embeddable 클래스에 사용되었는데요 이렇게 되면 JPA가 "doc"엔티티의 "doc_prop"속성을 접근할때 setter/getter를 사용하는 것이 아니라 필드로 접근하라고 접근 방식을 지정한 것이라고 이해하면 맞을까요?
- 해결됨JPA & Spring Data JPA 기초
7강에서 SecondaryTable을 왜 사용하지 모르겠습니다.
왜 SecondaryTable을 사용하는지 이해가 잘 안됩니다.예시가 writer라는 엔티티 클래스에 엔티티가 아닌 클래스 2개 각각을 하나의 타입으로해서writer라는 테이블의 속성으로 사용하는 것으로 이해되었습니다.그럼 6강에서 배운것 처럼 그냥 WriterInfo와 Address 클래스는 @Embeddable를 선언하고writer클래스에서@Embedded private Address addr;@Embedded private WriterInfo info;이렇게 해서 사용해도 될거 같다고 생각합니다.제가 제대로 이해하고 있는지가 궁금하고 혹시 이렇게 사용하지 않는 이유가 있는지 궁금합니다.
- 미해결JPA & Spring Data JPA 기초
JPA 실무 @Entity을 @Embeddable 대체하는 경우가 많은가요?
안녕하세요.실무에서 JPA 적용하여 프로젝트를 처음 진행하고 있습니다.제가 몰랐던 부분을 강의를 듣다 알게 되어 문의 드립니다. 저는 DB Table에 해당하는 class를 만들고 @Entity 정의를 통해 매핑한다고 생각했는데Table에 1:1 대응하는 class는 필요하겠지만 모든 class에 @Entity 정의를 할 필요는 없는것으로 이해했습니다.많은 테이블이 밸류매핑으로 처리가 가능할 것 같아서요(ex. User - UserDetail Table 같이 master-detail 관계 같은 경우.)14번째 강의 예제인 user - membership_card 테이블의 경우도 @Entity 대신 @Embeddable를 사용해도 될 것 같고user - best_pick Table 의 경우는 Entity 매핑을 하는 편이 어울릴 것으로 보여집니다. 1.위 내용처럼 실무에서 밸류매핑이 가능한 class의 경우 @Embeddable 어노테이션으로 정의하여 사용하는 경우가 많은 건가요? 2.관계에 따라 동일한 Table이 밸류 매핑 또는 엔티티 매핑으로 해야할 경우는 없는 걸까요?(User Table에 대응하는 user class가 엔티티가 되고 UserDetail Table에 대응하는 userDetail class가 @Embeddable 가 될 경우user - best_pick 관계에서 best_pick class에서 user class를 참조 할때 엔티티 매핑 외에 밸류 매핑을 할 수 있는 방법이 있을까요? 이미 user class는 엔티티인 상황인데 @Embeddable 정의를 통해 매핑을 다시 맺을 수 있는 것인지 헷갈리네요.. ㅜㅜ 정확한 이해를 위하여 문의 드렸습니다. 더불어 좋은 강의 감사합니다!! :)
- 해결됨JPA & Spring Data JPA 기초
도메인과 JPA 엔티티
도메인과 JPA 엔티티를 구분하려고 코드를 작성해봤습니다.@Repository@RequiredArgsConstructorpublic class OrderRepositoryImpl implements OrderRepository {private final OrderJpaRepository orderJpaRepository;@Override public void save(final OrderJpaEntity entity) {orderJpaRepository.save(entity);}@Overridepublic Optional<OrderJpaEntity> findById(final long orderId) {return orderJpaRepository.findById(orderId)}}이러한 방식으로 JpaRepository를 주입받고 OrderRepository를 구현하는 방식입니다.public interface OrderRepository {void save(final OrderJpaEntity entity);Optional<OrderJpaEntity> findById(final long orderId);} 그런데 이때 변경감지를 사용하려면 Order가 아닌 OrderJpaEntity를 반환해야하는데 이렇게 하면 결국 Repository에도 JPA 엔티티에 의존하기 때문에 분리를 잘 하지 못했다는 생각이 듭니다..혹시 도메인과 JPA 엔티티를 분리한다면 어떠한 방식으로 하시나요?
- 미해결JPA & Spring Data JPA 기초
상속 관계 엔티티 로직을 분기처리 하는 법?
안녕하세요 상속관계 엔티티를 다루는 방법에 대해 궁금한 점 있어 질문 드립니다상속관계의 엔티티가 존재하고, 자식 엔티티마다 서비스 로직이 다를 수 있을 때 어떻게 분기처리하는지 알고 싶어 질문 드립니다 @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "base_type") public abstract class BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String title; private String description; @Column(name = "base_type", updatable = false, insertable = false, length = 30) private String baseType; protected BaseEntity(Long id, String title, String description) { this.id = id; this.title = title; this.description = description; } } @Entity @DiscriminatorValue(value = "FIRST") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class FirstEntity extends BaseEntity{ private int like; @Builder public FirstEntity(Long id, String title, String description, int like) { super(id, title, description); this.like = like; } } @Entity @DiscriminatorValue(value = "SECOND") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter public class SecondEntity extends BaseEntity { private String redirectUrl; @Builder public SecondEntity(Long id, String title, String description, String redirectUrl) { super(id, title, description); this.redirectUrl = redirectUrl; } }이러한 상속구조 엔티티가 있고, 두 자식의 서비스 로직이 다를 수 있을 때컨트롤러에서 분기처리를 어떻게 하는지 알고 싶습니다@RestController @RequiredArgsConstructor @RequestMapping("/v1/test") public class TestController { private final TestService testService; @GetMapping public void findEntity(@RequestParam String type) { if(type.equalsIgnoreCase("first")) { } else if(type.equalsIgnoreCase("second")) { } //... //... //... } }만약 이러한 구조로 간다면, 자식클래스가 늘어났을 때 또 if문을 추가해야해서 효율적이지 못할 것 같아서요!지금 생각한 것은 상태 패턴을 이용하면 어떨까 하는데, 이게 좋은지 잘 모르겠습니다..public interface BaseContext { boolean support(String type); void executeFind(); }이렇게 인터페이스를 만들어주고@Component public class FirstContext implements BaseContext{ private static final String TYPE = "FIRST"; private final FirstService firstService; public FirstContext(FirstService firstService) { this.firstService = firstService; } @Override public boolean support(String type) { return TYPE.equalsIgnoreCase(type); } @Override public void executeFind() { firstService.find(); } }자식클래스의 상태를 구현하는 클래스를 만들어주고@RestController @RequiredArgsConstructor @RequestMapping("/v1/test") public class TestController { private final List<BaseContext> contexts; @GetMapping public void findEntity(@RequestParam String type) { BaseContext findContext = contexts.stream() .filter(context -> context.support(type)) .findAny() .orElseThrow(() -> new IllegalStateException("Error")); findContext.executeFind(); } } 컨트롤러에서는 이렇게 받아주면자식 엔티티가 늘어나도 if-else를 하지 않아도 된다고 생각했습니다다만, 자식 엔티티가 추가될 때 마다 Context를 추가해야 한다는 점과Context가 Service를 바라보고있어 Service가 수정되면 Context와 Service 2가지 모두 수정해야한다는 점이 마음에 걸립니다보통 상속관계의 엔티티를 다룰 때 어떤식으로 분기처리를 하나요??강사님이 아니시더라도 다른 수강생분들의 의견도 달아주시면 좋겠습니다!!