Gianmarco F.
Gianmarco F.

Reputation: 800

java.lang.IllegalArgumentException: Result Maps collection does not contain value for a certain mapper

I'm developing an application using MyBatis and I'm facing a real strange problem.
This already happened a few days ago but by uncommenting the following property on the dao-context2.xml I was able to solve

    <!-- <property name="mapperLocations" value="classpath*:src/main/resources/**/*.xml" /> -->

However, it came back and I'm not able to get past it, even if the line is commented or not.

Basic info

The DDL for that table is the following (Oracle flavour)

CREATE TABLE "T_APPLICATION_STATUS" 
   (    "STATUS" VARCHAR2(100) NOT NULL ENABLE, 
    "DATA_UPDATE" TIMESTAMP (6)
   ) ;

Which gets mapped to the following Java Bean

public class ApplicationStatus  {

    private String lockStatus;

    private Date dataUpdate;

    public String getLockStatus() {
        return lockStatus;
    }

    public void setLockStatus(String lockStatus) {
        this.lockStatus = lockStatus;
    }

    public Date getDataUpdate() {
        return dataUpdate;
    }

    public void setDataUpdate(Date dataUpdate) {
        this.dataUpdate = dataUpdate;
    }
}

Everything is mapped inside the ApplicationStatusMapper.xml, defined in the following way

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  

<mapper namespace="some.package.db.mappers.ApplicationStatusMapper">

    <resultMap type="some.package.db.model.ApplicationStatus" id="ApplicationStatus">
        <result property="lockStatus" column="STATUS"/> 
        <result property="dataUpdate" column="DATA_UPDATE"/> 
    </resultMap>
     
    <select id="getApplicationStatus" resultMap="ApplicationStatus">
     SELECT *
     FROM T_APPLICATION_STATUS
    </select> 
</mapper>

Which corresponds to the following Mapper Interface (Java flavour)

public interface ApplicationStatusMapper {
    
    @Update("UPDATE T_APPLICATION_STATUS "
            + "SET "
            + " STATUS = #{lockStatus}, "
            + " DATA_UPDATE = SYSDATE ")
    public void updateStatus(ApplicationStatus applicationStatus);

    @Select("SELECT STATUS AS lockStatus, DATA_UPDATE as dataUpdate FROM T_APPLICATION_STATUS")
    public ApplicationStatus getApplicationStatus();
    
}

All of this is mapped with this snippet in the dao-context2.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Dao Context -->

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="stringTrimmingTypeHandler" class="some.package.db.handler.StringTrimmingTypeHandler"/>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="typeHandlers" ref="stringTrimmingTypeHandler" />
        <property name="configLocation" value="classpath:mybatis-config.xml" />
        <!-- tolto il commento a mapperLocations perchè la query getMaxId() - SELECT_LAST_ID in TrasferimentoFondiMapper.java non funzionava -->
        <!-- <property name="mapperLocations" value="classpath*:src/main/resources/**/*.xml" /> -->
    </bean>

        <bean id="applicationStatusMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="mapperInterface" value="some.package.db.mappers.ApplicationStatusMapper" />
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    </bean>

    <bean id="datiAperturaContoMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
        <property name="mapperInterface" value="some.package.db.mappers.DatiAperturaContoMapper" />
        <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    </bean>
</beans>

And this is the mybatis-config.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="jdbcTypeForNull" value="NULL" />
        <!-- <setting name="mapUnderscoreToCamelCase" value="true"/> -->
    </settings>
</configuration>

Pom Dependencies

    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>2.0.6</version>
    </dependency>

The problem

When the user navigates to the application, the very first query that it launches explodes. Specifically, that very first query goes to check whether the application is in mainteneance or not.

Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for some.package.db.mappers.DatiAperturaContoMapper.DatiAperturaContoEX

In my project, I do have something related to DatiAperturaContoMapper and DatiAperturaContoEX, but they're no way related to the T_APPLICATION_STATUS mapper.

The result is the following error, which gets fired when the ApplicationStatusMapper.java is called. I'm also not able to setup, sadly, any kind of logging for MyBatis.

Things I tried

Some googling suggested me the following troubleshooting, which did not work:

  1. SQL syntax on the T_APPLICATION_STATUS (Though everything seems fine)
  2. mapperLocations that points to load everything (This seemed to work, though now on deploy it takes forever to load and brings to an OOM error)

I'm looking for any suggestion that could point me in the right direction. Does anybody know where I could start?

Upvotes: 4

Views: 13182

Answers (1)

Gianmarco F.
Gianmarco F.

Reputation: 800

Ok, it seems that it was an error by my side.
At least to my understanding, it seems that MyBatis loads the *Mapper.xml files not when the application is loaded, but when the first query is executed.
In this case, this exception

Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for some.package.db.mappers.DatiAperturaContoMapper.DatiAperturaContoEX

Was telling me that the Mapper for DatiAperturaContoMapper held some errors.

Specifically, this resulted in teh following

<resultMap id="DatiAperturaContoEx" type="some.package.db.model.DatiAperturaContoEx">
  my mapping...
</resultMap>


<select id="getDatiAperturaContoForAdempimenti" resultMap="DatiAperturaContoEX">
      my fancy query
</select>

The error was in the reference in the SELECT for the final X, which was in capital letter, while the id was DatiAperturaContoEx with a small x

Upvotes: 4

Related Questions