Skip to content

Error parsing SQL Mapper Configuration in mybatis

I am using mybatis framework in a servlet and the mybatis-config.xml file is unable to find the Student_mapper class.I applied all the paths including the package name and excluding it and also used the element in my mybatis-config.xml but it doesn’t work.I am still getting the same error.

Error building SqlSession.The error may exist in SQL Mapper Configuration 
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassNotFoundException: Cannot find class: mybatis/Student_mapper

Here’s my mybatis-config.xml file

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE configuration PUBLIC "-// Config 3.0//EN" "">

        <typeAlias type="mybatis.Student_mapper"
            alias="Student_mapper" />
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC" />
            <dataSource type="POOLED">
                <property name="driver" value="org.postgresql.Driver" />
                <property name="url"
                    value="jdbc:postgresql://localhost:5432/chitra" />
                <property name="username" value="postgres" />
                <property name="password" value="admin" />


        <mapper class="mybatis/Student_mapper" />

Here’s my Student_mapper interface

package mybatis;

import java.util.List;
import org.apache.ibatis.annotations.*;
public interface Student_mapper 
   final String getAll = "SELECT * FROM STUDENT"; 
   final String getById = "SELECT * FROM STUDENT WHERE ID = #{id}";
   final String deleteById = "DELETE from STUDENT WHERE ID = #{id}";
   final String insert = "INSERT INTO STUDENT (ID,NAME, COURSE, ROLL) VALUES (#{id},#{name}, #{course}, #{roll})";
   final String update = "UPDATE STUDENT SET NAME = #{name}, COURSE = #{course}, ROLL = #{roll} WHERE ID = #{id}";
   @Results(value = {
      @Result(property = "id", column = "ID"),
      @Result(property = "name", column = "NAME"),
      @Result(property = "course", column = "COURSE"),
      @Result(property = "roll", column = "ROLL")
   List<Student> getAll();

   @Results(value = {
      @Result(property = "id", column = "ID"),
      @Result(property = "name", column = "NAME"),
      @Result(property = "course", column = "COURSE"),
      @Result(property = "roll", column = "ROLL")
   Student getById(int id);
   void update(Student student);
   void delete(int id);
   //@Options(useGeneratedKeys = true, keyProperty = "id")
   void insert(Student student);


The mapper class needs to be a valid Java class name. Change your mybatis-config.xml to the following:

    <mapper class="mybatis.Student_mapper" />