[JPA] JPQL 다형성 쿼리

hi·2022년 10월 16일

TYPE

  • 조회 대상을 특정 자식으로 한정

ex) Item중 Book, Movie를 조회

JPQL

select i from Item i
where type(i) in (Book, Movie)

SQL

select i from i
where i.DTYPE in ('B', 'M')


TREAT (JPA 2.1)

  • 자바의 타입 캐스팅과 유사
  • 상속 구조에서 부모 타입을 특정 자식 타입으로 다룰 때 사용
  • from , where , select (hibernate 지원) 사용

ex) 부모인 Item과 자식 Book이 있다

JPQL

select i from Item i
where treat(i as Book).author = 'kim'

SQL

select i.* from Item i
where i.DTYPE = 'B' and i.author = 'kim'

0개의 댓글