java.lang.IllegalArgumentException: Result Maps collection already contains value for

1,525 views
Skip to first unread message

Colin Williams

unread,
Jan 2, 2013, 4:59:58 PM1/2/13
to mybati...@googlegroups.com
Hi all,

I think I must be doing something wrong, particularly since no one else on the internet seems to have this problem. I am trying to dynamically add Mappers to a Configuration after it has been initialized and used to generate a SqlSessionFactory.  According to my (inexperienced) look through the source code, there's nothing inherently preventing this from being possible, and it seems to be mentioned a few places in mailing lists and such.

The problem, however, is that I cannot get any of the mappers to register.  It throws the exception mentioned in the subject every time. I have the following files:


com/example/SavedUserSessionMapper.java
package com.example;

public interface SavedUserSessionMapper {
    public SavedUserSession getSessionByIdentifier(String identifier);

}
com/example/SavedUserSessionMapper.xml
<?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="com.xmlnamespace.panel.server.core.authentication.SavedUserSessionMapper">
    <select id="getSessionByIdentifier" parameterType="String">
        SELECT
            id,
            session_id AS sessionIdentifier,
            user_id as userIdentifier
        FROM user_sessions
        WEHRE session_id=#{value}
    </select>
</mapper>
database.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>
  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC"/>
      <dataSource type="POOLED">
        <property name="driver" value="org.h2.Driver"/>
        <property name="url" value="hdbc:h2:file:database"/>
        <property name="username" value="admin"/>
        <property name="password" value="admin"/>
      </dataSource>
    </environment>
  </environments>
</configuration>

And this code to wire everything together:
    // Instance variables
    private Configuration configuration = null;
    private SqlSessionFactory factory = null;       

        // ... initialize method...
        InputStream is = null;
        try {
            is = new FileInputStream("/path/to/database.xml");
           
            final XMLConfigBuilder builder = new XMLConfigBuilder(is);
            configuration = builder.parse();
            factory = new SqlSessionFactoryBuilder().build(configuration);
           
        } catch (final IOException e) {
            // Error handling
        }

    // And a method to register a new mapper
    public <T> void addMapper(Class<T> type) {
        configuration.addMapper(type);
    }
Then, later on in the code, I call the addMapper method of the above class:
database.addMapper(SavedUserSessionMapper.class);
And it throws this exception:
java.lang.IllegalArgumentException: Result Maps collection already contains value for com.example.SavedUserSessionMapper.getSessionByIdentifier-String
    at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:657)
    at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:629)
    at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:420)
    at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:200)
    at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.applyResultMap(MapperAnnotationBuilder.java:185)
    at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseResultsAndConstructorArgs(MapperAnnotationBuilder.java:164)
    at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parse(MapperAnnotationBuilder.java:118)
    at org.apache.ibatis.binding.MapperRegistry.addMapper(MapperRegistry.java:60)
    at org.apache.ibatis.session.Configuration.addMapper(Configuration.java:532)
    at com.example.DatabaseProvider.addMapper(Unknown Source)
    // Snip the rest of the stack is not related.

Now, I cannot find anyone else on the mailing lists or the rest of the internet with the same problem.  There was a bug report in the old Jira ([1]) with the same exception and that looks like it might apply, but that was fixed.

Thanks for any help,
--Colin

[1] - https://issues.apache.org/jira/browse/IBATIS-625

Ikchan Sim

unread,
Jan 2, 2013, 7:39:17 PM1/2/13
to mybati...@googlegroups.com
you missing result...

you declare configuration xml file that typeAlias. and declare mapper xml file resultClass or resultMap
mapper xml file is not exist result that <select /> element...

Colin Williams

unread,
Jan 2, 2013, 9:08:41 PM1/2/13
to mybati...@googlegroups.com
On 01/02/2013 05:39 PM, Ikchan Sim wrote:
you missing result...
I first had a resultType="com.example.SavedUserSession" in that select tag, because I thought that was the correct syntax.  However, the problem still happens when it has that, like this:
<select id="getSessionByIdentifier" parameterType="String" resultType="com.example.SavedUserSession">


you declare configuration xml file that typeAlias. and declare mapper xml file resultClass or resultMap
mapper xml file is not exist result that <select /> element...
I can't include the typeAlias tags in the configuration xml files, because I need to be able to add new Mappers/Types to the system that aren't known to the main configuration file. I tried using the fully qualified type name as above, and it seems to have no effect.  And just to clarify, the docs and the DTD say the attribute should be resultType, while you're mentioning resultClass.  I've tried it with resultClass, too, and that throws a parse error.

Thanks for the help,
--Colin

Ikchan Sim

unread,
Jan 3, 2013, 8:31:24 AM1/3/13
to mybati...@googlegroups.com

Please send relation files.
I tried sample coding.
2013. 1. 3. 오전 11:08에 "Colin Williams" <col...@i9technologies.com>님이 작성:

Colin Williams

unread,
Jan 4, 2013, 3:45:24 PM1/4/13
to mybati...@googlegroups.com
On 01/03/2013 06:31 AM, Ikchan Sim wrote:
>
> Please send relation files.
> I tried sample coding.
>
Hi Ikchan,

Thanks for your help. I spent the last day and a half trying to
duplicate the problem in a sample project, and couldn't manage to. I
never got the same error message. Luckily, though, I did manage to fix
the original problem, completely by accident. It seems that in an OSGi
environment, such as what I'm using, the package containing the mapper
class must be exported from the bundle.

Again, thanks for you help,
--Colin

Ikchan Sim

unread,
Jan 5, 2013, 9:00:19 AM1/5/13
to mybati...@googlegroups.com

You are welcome. It is my pleaser. Me too thank you your question.
2013. 1. 5. 오전 5:45에 "Colin Williams" <col...@i9technologies.com>님이 작성:

Qi Li

unread,
Oct 31, 2013, 5:10:35 AM10/31/13
to mybati...@googlegroups.com
How did you get it fixed.  I have the same problem
Reply all
Reply to author
Forward
0 new messages