There is no getter for property named

[Error] There is no getter for property named
property name에 맞는 getter가 없다는 에러가 발생했다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<insert id="insertBoard" parameterType="board.model.entity.BoardEntity">
INSERT INTO T_BOARD
(
TITLE,
CONTENTS,
CREATOR_ID
)
VALUES
(
#{TITLE},
#{CONTENTS},
'ADMIN'
);
</insert>
  • mapper.xml 파일에 위의 코드를 작성했더니 Error가 발생했다.

  • 원인: MyBatis 문법 에러로,
    parameterType으로 넘어온 BoardEntity 객체에 있는 property명
    쿼리문의 #{변수명}이 일치하지 않아서 발생한 에러이다.

  • cf) #{변수명}는 안에 있는 변수명과 일치하는 property를 찾아서 넣어주는 역할을 한다.

  • 해결 방법: parameterType의 property명과 #{}안의 변수명을 일치시켜준다.
    나의 경우에는 property명이 소문자이고, 쿼리문의 변수명은 대문자라서 에러가 발생했다.
    따라서, BoardEntity에 써준 그대로 #{}안에 넣도록 수정하여 에러를 해결했다.(같은 단어라도 대소문자에 따라 다르게 인식된다.)
  • #{TITLE} -> #{title}, #{CONTENTS} -> #{contents}로 수정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<insert id="insertBoard" parameterType="board.model.entity.BoardEntity">
INSERT INTO T_BOARD
(
TITLE,
CONTENTS,
CREATOR_ID
)
VALUES
(
#{title},
#{contents},
'ADMIN'
);
</insert>

참고 링크

[[Mybatis] getter for property named 에러 해결방법]]: https://yamea-guide.tistory.com/162