관리 메뉴

KorSA

MyBatis 변수명을 잘 썼는데도 There is no getter for property named 오류가 뜬다면.. 본문

Development Experience/DB

MyBatis 변수명을 잘 썼는데도 There is no getter for property named 오류가 뜬다면..

Praiv. 2022. 2. 28. 15:29
320x100

MyBatis의 Mapper.xml 파일을 작성할 때

<selectKey> 태그에서 keyProperty 속성으로 여러개의 key값을 지정하는 경우가 있다.

 

예를들어

<selectKey keyProperty="id, name, regDate">
...
</selectKey>

처럼 말이다.

 

이때 변수명을 잘 입력했음에도

org.mybatis.spring.MyBatisSystemException: 
nested exception is org.apache.ibatis.executor.ExecutorException: 
Error selecting key or setting result to parameter object. Cause: 
org.apache.ibatis.reflection.ReflectionException: 
There is no getter for property named...

오류가 뜨는 경우가 있다.

 

이 경우에는 keyProperty를 지정할 때 혹시 콤마(,) 다음에 띄어쓰기를 하진 않았는지 확인해보자.

 

MyBatis에서는 이 띄어쓰기도 변수명의 일부로 인식하기 때문에

위의 예에서 'regDate' 변수명을 ' regDate'로 인식해버린다.

 

나는 습관적으로 콤마(,) 다음에 띄어쓰기를 하기 때문에 이 오류가 발생했었다.

 

오류없이 작성하려면 띄어쓰기를 빼고 아래와 같이 작성해야 한다.

<selectKey keyProperty="id,name,regDate">
...
</selectKey>

 

728x90
728x90

'Development Experience > DB' 카테고리의 다른 글

MyBatis SelectKey returned no data 에러  (0) 2022.02.25
Comments