> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/jpa-basic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/jpa-basic/11.-2/undefined-1.md).

# 다형성 쿼리

TYPE

* 조회 대상을 특정 자식으로 한정\
  ex) Item 중에 Book, Movie를 조회할 때
* JPQL

```sql
select i from Item i 
where type(i) IN (Book, Movie)
```

* SQL

```sql
select i from i 
where i.DTYPE in (‘B’, ‘M’)
```

TREAT

* 자바의 타입 캐스팅과 유사
* 상속 구조에서 부모 타입을 특정 자식 타입으로 다룰 때 사용\
  \=>부모 클래스를 자식 클래스로 다운캐스팅 가능!
* FROM, WHERE, SELECT(하이버네이트 지원) 사용
* JPQL

```sql
select i from Item i
where treat(i as Book).auther = 'kim'
```

* SQL

```sql
select i.* from Item i
where i.DTYPE = 'B' and i.auther = 'kim'
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://heunnajo.gitbook.io/jpa-basic/11.-2/undefined-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
