[Version]
⦁ 2024.04.30 / [Spring Boot / Trouble Shooting] org.hibernate.query.SemanticException: Could not interpret path expression 's'
org.hibernate.query.SemanticException: Could not interpret path expression 's'
문제 원인
public List<Survey> findAllSurveys() {
return entityManager.createQuery("select s from Survey", Survey.class)
.getResultList();
}
설문지의 모든 데이터를 조회하는 과정에서 발생한 에러다. 원인을 파악해 본 결과 이 오류는 Hibernate에서 발생한 것으로 JPQL을 사용하여 쿼리를 작성할 때 발생한다. 즉, 엔티티 클래스가 정의되어 있지 않거나, 잘못된 속성을 참조할 때 발생하는 에러다.
해결 방법
public List<Survey> findAllSurveys() {
return entityManager.createQuery("select s from Survey s", Survey.class)
.getResultList();
}
JPQL을 위와 같이 작성했을 때, Survey 클래스에 대한 별칭이 지정되어 있지 않아 's'를 확인할 수 없어 발생한 문제이므로 해결하기 위해 Survey 클래스의 별칭을 지정해 주었다.