-
[Spring] o.h.e.jdbc.spi.SqlExceptionHelper - JDBC-90611:Specified column name was not found. - column 에러Spring 2021. 12. 8. 16:21
문제 상황
- 사용하는 DB_TABLE 에는 NAME, AGE, ADRESS, GENDER, PHONE_NUMBER 5개의 컬럼이 존재 한다.
- 스프링 프로젝트에서 JPA - nativeQuery를 사용해서 필요한 column 정보만 가져오게 하였다.
@Query(value = "SELECT NAME, AGE, ADRESS FROM DB_TABLE WHERE NAME = :name", nativeQuery = true) public Entity getNameAgeAdress(@Param("name") String name);
- 해당 메서드를 실행 하였더니 다음과 같은 오류가 발생하였다.
16:09 ERROR o.h.e.jdbc.spi.SqlExceptionHelper - JDBC-90611:Specified column name was not found. - GENDER 16:09 WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved [org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query]
- Entity에는 분명히 gender가 mapping이 되어 있는데 왜 column을 찾을 수 없는다는 에러가 뜨는 것일까.
- 이유는 간단했다. JPA와 Hibernate를 통해서 DB 정보를 가져올 때는 모든 컬럼 정보를 다 가져와야 한다.
해결 방법
- 필요 없는 column 정보라도 쿼리를 통해 가져와야 한다.
@Query(value = "SELECT NAME, AGE, ADRESS, GENDER, PHONE_NUMBER FROM DB_TABLE WHERE NAME = :name", nativeQuery = true) public Entity getNameAgeAdress(@Param("name") String name);
- DB_TABLE 의 5개 column 중에 3개의 column만 select 하게 해서 에러가 났는데 나머지 2개의 column도 가져오게 하면 에러없이 정상적으로 쿼리가 수행된다.
*누락되는 column없이 모든 column 데이터를 가져오게 쿼리를 수정해라!!!
'Spring' 카테고리의 다른 글
[Spring] WebClient 사용시 http:// 프로토콜이 https:/로 자동 변환되는 이슈 (0) 2023.04.07 [Spring Logging] Slf4j - log4j2 사용 시 기존 logback, log4j 와 충돌 에러 (0) 2021.11.29 [Spring] Logging slf4j - log4j, logback, log4j2 (0) 2021.11.29 [Spring] Native Query 사용 시 Failed to convert from type [java.lang.Object[]] to type 에러 (0) 2021.10.21 [Spring] JPA update query error (0) 2021.10.14