title: mybatis org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
body: <p>I am using Spring MVC with Spring-Mybatis for performing basic CRUD operations using Annotations(<code>@Insert</code>, <code>@Select</code> etc) and getting this following exception </p>
  
  <p><code>org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):</code></p>
  
  <p>Here's a related question, <a href="https://stackoverflow.com/questions/20427210/mybatis-spring-mvc-application-getting-invalid-bound-statement-not-found">mybatis spring mvc application, getting Invalid bound statement (not found)</a> but that doesn't solve my problem as it uses XML(<code>UserMapper.xml</code>) mapping for queries where I use java interfaces(<code>UserMapper.java</code>) with Annotations.</p>
  
  <p><strong>Exception stacktrace:</strong></p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.spring.mybatisdemo.mappers.UserMapper.selectNationality
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:801)
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
      at org.eclipse.jetty.server.handler.ContextHandler.__doHandle(ContextHandler.java:1126)
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java)
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1060)
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
      at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
      at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
      at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
      at org.eclipse.jetty.server.Server.handle(Server.java:509)
      at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:288)
      at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:240)
      at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:539)
      at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
      at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.spring.mybatisdemo.mappers.UserMapper.selectNationality
      at org.apache.ibatis.binding.MapperMethod$SqlCommand.&lt;init&gt;(MapperMethod.java:196)
      at org.apache.ibatis.binding.MapperMethod.&lt;init&gt;(MapperMethod.java:44)
      at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59)
      at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
      at com.sun.proxy.$Proxy41.selectNationality(Unknown Source)
      at com.spring.mybatisdemo.service.UserServiceImpl.selectNationalityById(UserServiceImpl.java:69)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.zeroturnaround.javarebel.fY.invoke(JRebel:1114)
      at java.lang.reflect.Method.invoke(Method.java)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
      at com.sun.proxy.$Proxy43.selectNationalityById(Unknown Source)
      at com.spring.mybatisdemo.controller.UserController.getUsers(UserController.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
  </code></pre>
  
  <p><strong>springConfig.xml</strong></p>
  
  <pre><code>&lt;bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"&gt;
    &lt;property name="dataSource" ref="dataSource" /&gt;
    &lt;property name="typeAliasesPackage" value="com.spring.mybatisdemo.model"/&gt;
    &lt;property name="mapperLocations" value="classpath*:com/spring/mybatis/mappers/*.xml" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"&gt;
    &lt;constructor-arg index="0" ref="sqlSessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"&gt;
    &lt;property name="basePackage" value="com.spring.mybatisdemo.mappers" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p><strong>Nationality</strong> POJO class,</p>
  
  <pre><code>public class Nationality {  
    private Long nationalityId;
    private String name;
  
    //ignoring getters and setters
  }
  </code></pre>
  
  <p>I'm using annotation for the queries and below is my relevant code from UserMapper.java interface,</p>
  
  <pre><code>@Select("SELECT nationalityId, name FROM nationality where nationalityId = #{nationalityId} ")
  public Nationality selectNationality(Long nationalityId);
  </code></pre>
  
  <p>Calling the above method like,</p>
  
  <pre><code>Nationality nationality = userService.selectNationalityById(new Long("1"));
  </code></pre>
  
  <p>And in <code>UserServiceImpl.java</code> I have injected the UserMapper bean and use it like,</p>
  
  <pre><code>userMapper.selectNationality(nationalityId);
  </code></pre>
  
  <p>The same query I used for selecting the <code>teamById</code> work fine,</p>
  
  <pre><code>userMapper.getTeamById(teamId)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Select("SELECT teamId, name FROM TEAM WHERE teamId = #{teamId}")
  public Team getTeamById(Long teamId);
  </code></pre>
  
  <p>and the corresponding teamById query in console,</p>
  
  <pre><code>[artifact:mvn] 2015-11-02 18:51:20 DEBUG SpringManagedTransaction:54 - JDBC Connection [com.mysql.jdbc.JDBC4Connection@1e846b60] will be managed by Spring
  [artifact:mvn] 2015-11-02 18:51:20 DEBUG getTeamById:54 - ==&gt;  Preparing: SELECT teamId, name FROM TEAM WHERE teamId = ? 
  [artifact:mvn] 2015-11-02 18:51:20 DEBUG getTeamById:54 - ==&gt; Parameters: 4(Long)
  [artifact:mvn] 2015-11-02 18:51:20 DEBUG getTeamById:54 - &lt;==      Total: 1
  </code></pre>
  
  <p>I can't get why only the Nationality has this problem while the same method for Team class works fine. What could be the problem in my code for fetching the Nationality data?</p>