Carmageddon
Carmageddon

Reputation: 2849

Mybatis: no Result Maps were found for the Mapped Statement

I had to add a ping query to ensure db did not timeout, to existing mapper files and code, this looks as follows:

In the mapper XML:

<select id="pingTest" statementType="CALLABLE">
    SELECT 1 FROM DUAL
</select>

Interface:

void pingTest() throws SQLException;

Implementation (inside LogInputDao class):

    public void pingTest() throws SQLException {
    SqlSession session = null;

    SqlSessionFactory sqlSessionFactory = MyBatisDBConfig.getSqlSessionFactory();

    session = sqlSessionFactory.openSession();

    LogInputMapper mapper = session.getMapper(LogInputMapper.class);
    mapper.pingTest();
}

logInputDao.pingTest()

Brings out the error:

### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.example.proj.name.dbservice.mappers.LogInputMapper.pingTest'.  It's likely that neither a Result Type nor a Result Map was specified.
### The error may exist in com/example/proj/dbservice/config/LogInputMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT 1 FROM DUAL
### Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.example.proj.name.dbservice.mappers.LogInputMapper.pingTest'.  It's likely that neither a Result Type nor a Result Map was specified.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:59)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:95)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
        at com.sun.proxy.$Proxy18.pingTest(Unknown Source)
        at com.example.proj.name.dbservice.dao.LogInputDao.pingTest(LogInputDao.java:52)
.....

I dont need the results, either way I am not sure exactly how to fix this, first time I do something with MyBatis

Upvotes: 0

Views: 3630

Answers (1)

Sergey Nemchinov
Sergey Nemchinov

Reputation: 1616

As @ave said already above, in select statements MyBatis expects some data to return and it needs to map it. One of them is necessary. So you have to add a resultType or resultMap tag and remove unnecessary statementType="CALLABLE".

Here is an example of mapping:

<select id="pingTest" resultType="int">
    SELECT 1 FROM DUAL
</select>

Upvotes: 1

Related Questions