상세 컨텐츠

본문 제목

[MyBatis] PersistenceException 에러

개발/Database

by 대충고양이짤 2015. 6. 15. 18:03

본문

문제 상황


Mybatis + MariaDB 연동 중에 아래와 같이 PersistenceException 관련 에러가 발생하였다.




에러로그


org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 

### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.test.CountValue

### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.test.CountValue

at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)

at com.sun.proxy.$Proxy25.insert(Unknown Source)

at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155)

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

at com.sun.proxy.$Proxy29.countValue(Unknown Source)

....

Caused by: org.apache.ibatis.exceptions.PersistenceException: 

### Error updating database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.test.CountValue

### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.test.CountValue

at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:147)

at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:134)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)

... 64 more

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.test.CountValue

at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:660)

at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:495)

at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:488)

at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:144)

... 70 more




test.xml


<select id="getcount" parametertype="java.lang.String" resulttype="java.lang.Integer">

SELECT COUNT(*)

FROM testvalue

WHERE valueID = #{valueID}

</select>



test.java


@Override

public long getCount(String valueID) throws Exception {

long cnt = 0;

cnt = (long)query.selectOne(Name + "getCount", valueID);

return cnt;

}





문제 원인


test.java와 test.xml에서 사용한 id의 대소문자 값이 동일하지 않았다. (스펠링은 같음)

혹시나 스펠링이 다를까봐 ctrl+C로 id 복사 후 찾아 봤을 때도 잘 검색이 되었기 때문에 에러인지 바로 인식을 못했다.

별것 아니지만 이런류의 에러가 시간+에너지를 잡아먹기 딱 좋은듯 하다.



문제 해결


test.xml


<select id="getCount" parameterType="java.lang.String" resultType="java.lang.Long">

SELECT COUNT(*)

FROM testvalue

WHERE valueID = #{valueID}

</select>




관련글 더보기

댓글 영역