Mapped Statements collection does not contain value ....

2,617 views
Skip to first unread message

Josh Kamau

unread,
Feb 22, 2011, 12:28:32 PM2/22/11
to mybati...@googlegroups.com
Hi there,

I would love to know what causes this error. I have spent hours on it but i cant figure it out.

Here is my Mapper interface ;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.enlliance.inventory.mappers;

import java.util.HashMap;
import java.util.List;

/**
 *
 * @author joshua
 */
public interface SettingMapper {

    public List<HashMap> getSettingValue(String setting);

    public void saveSetting(HashMap<String, Object> params);

    public void updateSetting(HashMap<String, Object> params);

}



Here is my xml mapper

<?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.enlliance.inventory.mappers.SettingMapper">

       <select id="getSettingValue" parameterType="string" resultType="HashMap">
           SELECT
            s.value as value
           FROM en_setting s
           WHERE s.setting = #{setting};
       </select>

       <insert id="saveSetting" parameterType="HashMap">
            INSERT INTO en_setting(setting, value, active, created, updated, createdby, updatedby)
            VALUES (#{setting}, #{value}, true, now(), now(), #{userId}, #{userId});
       </insert>

       <update id="updateSetting" parameterType="HashMap">
           UPDATE en_setting SET value = #{value}, active = #{active}
           updated= now() WHERE setting LIKE #{setting} ;
       </update>

</mapper>


java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.enlliance.inventory.mappers.SettingMapper.getSettingValue
        at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:593)
        at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:393)
        at org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:160)
        at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:37)
        at $Proxy12.getSettingValue(Unknown Source)
        at com.enlliance.inventory.dao.impl.SettingsDaoImpl.getSettingValue(SettingsDaoImpl.java:30)
        at com.enlliance.inventory.SettingTestCase.testGettingSettingValueBySetting(SettingTestCase.java:21)
        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:616)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        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:616)
        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)

Thanks in advance.

Josh.

Josh Kamau

unread,
Feb 22, 2011, 1:32:11 PM2/22/11
to larry....@gmail.com, mybati...@googlegroups.com
Thanks Larry.

 I realized my mistake. i had used the same namespace in 2 different mappers - I have been doing quite a bit of copy pasting.

Thanks
Josh.

On Tue, Feb 22, 2011 at 9:11 PM, Larry Meadors <larry....@gmail.com> wrote:
The three names have to match:
 - interface = com.enlliance.inventory.mappers.SettingMapper.class
 - mapper file = /com/enlliance/inventory/mappers/SettingMapper.xml
 - mapper namespace = com.enlliance.inventory.mappers.SettingMapper

If they don't match, it won't work.

Larry

Larry Meadors

unread,
Feb 22, 2011, 1:11:24 PM2/22/11
to mybati...@googlegroups.com, Josh Kamau

Josh Kamau

unread,
Feb 22, 2011, 12:58:05 PM2/22/11
to mybati...@googlegroups.com
Hi All,

I renamed my mapper to SettingsMapper.java and SettingsMapper.xml and it worked. I figured that if i rename , it will be reregistered. I dont know what was the problem and why it worked.  Anyone who knows why?

Josh.

gunnlaugursig

unread,
May 17, 2011, 5:31:45 AM5/17/11
to mybati...@googlegroups.com
Hello,

Josh I have the same problem.

# My mapper interface
public interface UserInfoMapper {

public UserInfo getUserInfoBySnb(String snb);
public UserInfo getAllUserInfoBySnb(String snb);
public UserInfo getUserInfoByImsi(String imsi);
}

# Then my datasourceContext.xml
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="is.simnn.act.web.ngs.mappers" />
</bean>

# My UserInfoMapper.xml


<?xml version="1.0" encoding="UTF-8"?>

&lt;!DOCTYPE mapper PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;&gt;

<mapper namespace="is.simnn.act.web.ngs.mappers.UserInfoMapper">

<select id="getUserInfoBySnb" parameterType="string"
resultType="userInfo">
SELECT
port.snb,
port.timestamp,
port.user_type,
port.real_exch,
port.act_exch,
port.dev_type,
port.rc
FROM
port
WHERE
port.snb = #{snb}
</select>

<select id="getAllUserInfoBySnb" parameterType="string"
resultType="userInfo">
SELECT
p.snb,
p.real_exch,
p.act_exch,
p.user_type,
p.dev_type,
p.dev_number,
p.main_number,
p.ea_int,
p.ea_nat,
p.TIMESTAMP,
p.timestamp_comp,
p.rc,
p.bsnb,
p.black,
p.out_go_num,
p.imsi,
p.subscr_type,
p.dual_main,
p.dual_sec,
p.sec_exchange,
p.special_scl,
p.name_of_user,
p.status_id,
p.category_id,
p.head_number,
p.status_id_tstamp,
ngs.subscr_subtype
FROM
port p inner join ngs_add_data ngs
ON ngs.snb = p.snb
WHERE
p.snb = #{snb}
</select>

<select id="getUserInfoByImsi" parameterType="string"
resultType="userInfo">
SELECT
snb,
timestamp,
user_type,
real_exch,
act_exch,
dev_type,
rc
FROM
port
WHERE
imsi = #{imsi} AND port.status_id = 1
</select>

</mapper>

# Here is my mybatis-config.xml


<?xml version="1.0" encoding="UTF-8"?>

&lt;!DOCTYPE configuration
PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot;
&quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&gt;

<configuration>
<settings>

<setting name="lazyLoadingEnabled" value="false" />
</settings>
<typeAliases>
<typeAlias alias="userInfo"
type="is.simnn.act.web.ngs.domain.UserInfo" />
</typeAliases>

</configuration>

Do you see anything wrong with my configuration?

Thanks
Gunnlaugur

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Mapped-Statements-collection-does-not-contain-value-tp2553948p2951798.html
Sent from the mybatis-user mailing list archive at Nabble.com.

gunnlaugursig

unread,
May 17, 2011, 6:39:02 AM5/17/11
to mybati...@googlegroups.com
Hello,

Josh I have the same problem.

# My mapper interface
public interface UserInfoMapper {

public UserInfo getUserInfoBySnb(String snb);
public UserInfo getAllUserInfoBySnb(String snb);
public UserInfo getUserInfoByImsi(String imsi);
}

# Then my datasourceContext.xml
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="is.simnn.act.web.ngs.mappers" />
</bean>

# My UserInfoMapper.xml


<?xml version="1.0" encoding="UTF-8"?>

<mapper namespace="is.simnn.act.web.ngs.mappers.UserInfoMapper">

</mapper>

<?xml version="1.0" encoding="UTF-8"?>

&lt;!DOCTYPE configuration
PUBLIC &quot;-//mybatis.org//DTD Config 3.0//EN&quot;
&quot;http://mybatis.org/dtd/mybatis-3-config.dtd&quot;&gt;

<configuration>
<settings>

<setting name="lazyLoadingEnabled" value="false" />
</settings>
<typeAliases>
<typeAlias alias="userInfo"
type="is.simnn.act.web.ngs.domain.UserInfo" />
</typeAliases>

</configuration>

Do you see anything wrong with my configuration?

Thanks
Gunnlaugur

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Mapped-Statements-collection-does-not-contain-value-tp2553948p2951964.html

Poitras Christian

unread,
May 18, 2011, 8:36:29 AM5/18/11
to mybati...@googlegroups.com
This error sometime appears on the first query with MyBatis 3.0.4. This is fixed in 3.0.5-SNAPHOT.

Christian

-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de gunnlaugursig
Envoyé : May-17-11 6:39 AM
À : mybati...@googlegroups.com
Objet : Re: Mapped Statements collection does not contain value ....

Josh Kamau

unread,
May 18, 2011, 8:40:04 AM5/18/11
to mybati...@googlegroups.com
Hi Gunn,

I never quite discovered what was wrong. It worked and never failed again.

Thanks for your insight.
Josh.

gunnlaugursig

unread,
May 18, 2011, 8:51:33 AM5/18/11
to mybati...@googlegroups.com
I manage to get it working.

My problem was that I had my UserInfoMapper.xml under
src/main/resources/META-INF/is/siminn/act/web/ngs/mappers
The mapper file has to be in the same directory as the interface ie.
src/main/java/is/siminn/act/web/ngs/mappers

This solved it. But then another problem came up. For some reason one of the
selects from the mapper constantly returns NullPointerException
I've tested it using SQL Developer and it works fine but I have not found
the reason for it's failure.

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Mapped-Statements-collection-does-not-contain-value-tp2553948p2956786.html

Larry Meadors

unread,
May 18, 2011, 8:58:05 AM5/18/11
to mybati...@googlegroups.com
On Wed, May 18, 2011 at 6:51 AM, gunnlaugursig <gunnla...@gmail.com> wrote:
> My problem was that I had my UserInfoMapper.xml under
> src/main/resources/META-INF/is/siminn/act/web/ngs/mappers
> The mapper file has to be in the same directory as the interface ie.
> src/main/java/is/siminn/act/web/ngs/mappers

No, that's not right.

It must be in the same package, not the same directory. If you have
src/main/java and src/main/resources on the class path, then you'd
want this:
- src/main/java/is/siminn/act/web/ngs/mappers/UserInfoMapper.java
- src/main/resources/is/siminn/act/web/ngs/mappers/UserInfoMapper.xml

Then the namespace for the xml file would be
"is.siminn.act.web.ngs.mappers.UserInfoMapper".

Larry

gunnlaugursig

unread,
May 18, 2011, 9:29:18 AM5/18/11
to mybati...@googlegroups.com
Yeah you are right Larry.
Sorry thats what I meant.
I moved the xml to the same package.

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Mapped-Statements-collection-does-not-contain-value-tp2553948p2956933.html

wass

unread,
Sep 19, 2011, 7:13:12 AM9/19/11
to mybati...@googlegroups.com
Larry,

i should use this namespace for my mapper
"is.siminn.act.web.ngs.mappers.UserInfoMapper" but how should i register
this mapper at the configuration.xml file?

--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Mapped-Statements-collection-does-not-contain-value-tp2553948p3348269.html

Paul Krause

unread,
Feb 13, 2013, 4:53:09 PM2/13/13
to mybati...@googlegroups.com

The culprit turned out to be the maven clean plugin.  It was wiping out all the generated xml files created by MyBatis Generator.  Of course, these files were recreated by the generate-sources, but without the handwritten code that MGB so carefully had been merging.

The solution is to tell the clean plugin to leave the xml files created by MBG alone.

<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>${project.build.directory}</directory>
<excludes>
<exclude>generated-sources/mybatis-generator/**/*.xml</exclude>
</excludes>
</fileset>
<fileset>
<directory>${project.build.outputDirectory}</directory>
</fileset>
<fileset>
<directory>${project.build.testOutputDirectory}</directory>
</fileset>
<fileset>
<directory>${project.build.outputDirectory}</directory>
</fileset>
</filesets>
</configuration>
</plugin>
Reply all
Reply to author
Forward
0 new messages