작성
·
436
0
싱글 테이블 전략을 사용하면 db에 저장시 dtype이 생기는데요
테스트를 하던 도중, Book 타입을 조회할려고 코드를 작성했는데 dtype은 엔티티로 접근을 못하더라구요..?
접근을 못하니 JPQL으로 작성하면 오류가 납니다 ㅜ
dtype으로 조회하고 싶을 때는 어떻게 해야하나요?
제가 작성한 코드
public void itemFindTest() {
Item book = new Book("JPA", 10000, 10, "김영한", "123");
Item album = new Album("베토벤", 20000, 20, "베토벤", "교향곡");
em.persist(book);
em.persist(album);
em.flush();
em.clear();
List<Item> resultList = em.createQuery(
"select i from Item i where i.dtype = :type", Item.class
)
.setParameter("type", "BOOK")
.getResultList();
}
디비에는 아래와 같이 잘 저장되어있습니다.
답변 1
0
아 저건 제 오타입니다 원래는 book으로 시도했었고
위에 질문글에 말씀드린것처럼
i.dtype 에서 dtype이 인식이 안됩니다.
관련 오류 코드도
org.hibernate.QueryException: could not resolve property: dtype of: jpa.practice3.domain.item.Item [select i from jpa.practice3.domain.item.Item i where i.dtype = :type]
java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: dtype of: jpa.practice3.domain.item.Item [select i from jpa.practice3.domain.item.Item i where i.dtype = :type]
라고 뜨구요
원래 dtype은 JPQL에서 접근을 못하는지에 대한 질문입니다!