재유's

[Error : Mybatis] Mapped Statements collection does not contain value for... 본문

IT Story/ : : Error

[Error : Mybatis] Mapped Statements collection does not contain value for...

Stella_NY 2019. 1. 3. 11:41

MyBatis에서 Mapped Statements collection does not contain value for... 이라는 에러가 떳다.



어떤 에러인지는 알고있었지만

select은 되는데 왜 insert문만 안되는거야 하면서 뭔가 문제냐고 하면서 보았다.


원인은

Mapper.xml에 insert 태그 id를 add_userInfo라고 정의를 했는데 에 '(따옴표) 가 앞에 들어가있어서 그걸 발견하지 못했었다. (눈이... ㅜㅜ)

( => add_userInfo가 아닌 'add_userInfo로 정의ㅜㅜ)

2시간동안...ㅜㅜ


위와 같이 

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for ...이라는 에러가 뜨면


다음과 같은 상황일 때 에러가 발생한다.

1. Mapper id가 다를경우

mapper파일(MyBatis의 쿼리문을 등록한 XML파일)에 <select id='' ...>에 id와 mapper파일에 직접 접근하는 java파일(DAO나 Service)에 적어놓은 id값이 다른경우

2. Parameter와 beans의 필드명이 다른 경우

3. Mapper파일(MyBatis의 쿼리문을 등록한 XML파일)에 정의된 네임스페이스(namespace)와 

   mapper파일에 직접 접근하는 java파일(DAO나 Service)에서 호출하는 네임스페이스(namespace)가 다른 경우

4. MyBatis config.xml파일에 mapper가 정의 되어 있지 않거나 Sepelling이 틀린 경우

5. Mapper에 정의된 namespace 명칭이 같이 Application내에 중복 될 경우

(출처: http://javaking75.blog.me/220315971085)

Comments