반응형
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
- 신문법 abap
- for all entries in
- abap
- sap memory
- controller
- 구글 보안 api 활용
- value base corresponding
- spring
- springSecurityFilterChain 오류
- SpringMVC
- optional
- Testcode
- SAP
- BindingResult
- abap면접
- abap memory
- memory 정리
- spring MVC
- jpa
- memory변수명 변경
- MVC
- abap value in field Data Class error
- n+1
- 김영한
- new syntax
- application-properties
- @Controller
- .orelseThrow
- Validation
- mapping corresponding
Archives
- Today
- Total
SAP공장
@Inheritance(strategy = Inheritance.Type.JOINED) 전략 본문
[WEB]Back-end/JPA
@Inheritance(strategy = Inheritance.Type.JOINED) 전략
ABAP,ODATA,BTP 2022. 1. 8. 12:52반응형
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 |