반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 쿠키란
- 세션의 정의
- 세션이란
- n+1
- jpa
- 401오류
- 김영한
- spring
- filter vs interceptor
- 구글 보안 api 활용
- 필터vs인터셉터
- 쿠키의 정의
- 세션vs쿠키
- springSecurityFilterChain 오류
- Validation
- .orelseThrow
- @Controller
- SpringMVC
- MVC
- java.lang.AssertionError
- 필터의 정의
- Testcode
- 인터셉터의 정의
- controller
- optional
- spring MVC
- application-properties
- BindingResult
- 유연한 컨트롤러1 - v5
- abap value in field Data Class error
Archives
- Today
- Total
ABAP DUMP ERROR 24시
@Inheritance(strategy = Inheritance.Type.JOINED) 전략 본문
반응형
1. @Inheritance(strategy = Inheritance.Type.JOINED) 전략
2. @Inheritance(strategy = Inheritance.Type.SINGLE_TABLE) 전략
1. JOINED 전략
Item |
Item_id(pk) name price Dtype |
Album | Movie | Book |
Item_id(pk,fk) Artist |
Item_id(pk,fk) director actor |
Item_id(pk,fk) author isbn |
package jpabook.jpashop.inheritance;
import javax.persistence.*;
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn
public class Item {
@Id@GeneratedValue
private Long id;
private String name;
private int price;
}
<Item>
package jpabook.jpashop.inheritance;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
@DiscriminatorValue("A")
public class Album extends Item {
private String artist;
}
<Album>
extends 를 통해 부모 클래스를 상송 받으면 부모의 pk를 , 자식은 pk ,fk로 상속받아 쓸수있다.
-Q. Dtype은 뭐야?
A. Dtype은 부모입장에서 조회해봤을때 어떤 자식에게서 data가 들어왔는지 확인이 가능하다!
사용방법
부모 타입에 @DiscriminatorColumn() 어노테이션을 넣고
자식타입에 @Discriminatorvalue를 사용하면
부모 조회시 어떤 자식에서 왔는지 확인이 가능하다.
@Disciminatorvalue("A") => 라고 쓰면 Item 조회시 Dtype에 Album은 A라고 나온다.
Q. joined 전략의 장단점
반응형
'[WEB]Back-end > JPA' 카테고리의 다른 글
JPA Proxy가 뭐야? 왜 사용해? (0) | 2022.01.13 |
---|---|
다양한 연관관계 매핑 (0) | 2022.01.10 |
@joinColumn, @mappedby, 양방향 Mapping시 주의해야할점 (0) | 2022.01.07 |
@Table과 @Column 의 차이 (0) | 2022.01.04 |
JPA 정리_영속성 컨텍스트 (0) | 2022.01.01 |
Comments