JPQL 다형성 쿼리
{item} //item 을 상속받는 클래스들의 공통된 속성
-name
-price
{album}
-artist
{movie}
-director
-actor
{book}
-author
-isbn
위 같은 경우 JPA가 특별한 기능을 제공한다.
1.조회대상을 트정 자식으로 한정할수 있다(type 한정)
예)item 중에 book , movie를 조회한다
(JPQL)
select from item i
where type (i) IN (book , movie)
//where type (i) IN (book , movie) 문법으로 Item 타입들중 book과 movie만을 조회
(SQL)
select i from item i
where i.dtype in ('b','m')
2.Treat(JPA 2.1)
-자바의 타입캐스팅과 유사
-상속구조에서 부모타입을 특정 자식타입으로 다룰 때 사용
-from , where , select (하이버네이트 지원) 사용
예)부모인 Item과 자식 book이 있다.
(JPQL)
select i from item i
where treat(i as book).author = 'kim'
//where treat(i as book).author = 'kim' 문법으로 i중 book만 찾아서 특정 필드값만 가져온다.
(SQL)
select i.* from item i
where i.dtype = 'b' and i.author ='kim'
'JPA' 카테고리의 다른 글
| 2월 20일 JPQL - named쿼리 (정적쿼리) (0) | 2023.02.20 |
|---|---|
| 2월 17일 JPA JPQL 엔티티 직접 사용 (0) | 2023.02.17 |
| 2월 16일 JPA JPQL 페치조인의 특징과 한계 (0) | 2023.02.16 |
| 2월 16일 JPA 일대다 관계, 컬렉션 페치 조인 (0) | 2023.02.16 |
| 2월 16일 JPA JPQL fetch Join (0) | 2023.02.16 |