emacarron / old-google-code-issues

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

include sql #250

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
3.0.4 and 3.0.5, mybatis-spring-1.0

Please describe the problem.  Unit tests are best!
[3.0.4]
java.lang.IllegalArgumentException: XML fragments parsed from previous mappers 
does not contain value for UserInfo.columns
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:593)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler.handleNode(XMLStatementBuilder.java:155)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseDynamicTags(XMLStatementBuilder.java:85)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:43)
    at org.apache.ibatis.session.Configuration.parseStatementNodes(Configuration.java:513)
    at org.apache.ibatis.session.Configuration.buildStatementsForNamespace(Configuration.java:502)
    at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:456)
    at org.apache.ibatis.session.Configuration.getMappedStatementNames(Configuration.java:380)
    at com.gm.security.dao.test.DaoTestCase.testMapper(DaoTestCase.java:150)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

[3.0.5]
org.apache.ibatis.builder.xml.IncompleteStatementException: Could not find SQL 
statement to include with refid 'UserInfo.columns'
    at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler.handleNode(XMLStatementBuilder.java:172)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseDynamicTags(XMLStatementBuilder.java:90)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:45)
    at org.apache.ibatis.session.Configuration.buildAllStatements(Configuration.java:464)
    at org.apache.ibatis.session.Configuration.getMappedStatementNames(Configuration.java:376)
    at com.gm.security.dao.test.DaoTestCase.testMapper(DaoTestCase.java:150)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.IllegalArgumentException: XML fragments parsed from 
previous mappers does not contain value for UserInfo.columns
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:554)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler.handleNode(XMLStatementBuilder.java:161)
    ... 33 more

[my sqlmapper.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="UserInfo">
    <sql id="UserInfo.columns">
    <![CDATA[
    user_info_id,login_account,user_name,first_name,last_name,login_pwd,login_email,user_type,register_time,user_status
    ]]>
    </sql>

    <select id="UserInfo.getById" resultMap="RM.UserInfo">
        SELECT
        <include refid="UserInfo.columns" />
        FROM user_info WHERE user_info_id = #{id}
    </select>

    <resultMap id="RM.UserInfo" type="com.gm.security.model.UserInfo">
        <result property="userInfoId" column="user_info_id" />
        <result property="loginAccount" column="login_account" />
        <result property="userName" column="user_name" />
        <result property="firstName" column="first_name" />
        <result property="lastName" column="last_name" />
        <result property="loginPwd" column="login_pwd" />
        <result property="loginEmail" column="login_email" />
        <result property="userType" column="user_type" />
        <result property="registerTime" column="register_time" />
        <result property="userStatus" column="user_status" />
    </resultMap>
</mapper>

What is the expected output? What do you see instead?
<sql id="UserInfo.columns">
or
<include refid="UserInfo.columns" /> does not work

UserInfo.columns|UserInfo_columns|cloumns|whatever namespace  ,I have tried any 
possible

[junit code:]
@Test
public void testMapper() {
    //All sql mapper
    Collection<String> list = sqlSessionFactory.getConfiguration().getMappedStatementNames();
    for (Iterator iterator = list.iterator(); iterator.hasNext();) {
        String string = (String) iterator.next();
        System.out.println("SQL_mapper: >>>>>>"+string); //did not see UserInfo.columns
    }
    //do select
    UserInfo user = userInfoDao.getById(10L);
    System.out.println(user.getFirstName());
}

Please provide any additional information below.

mybatis 3.0.3 is ok , but can not integration mybatis-spring-1.0

Original issue reported on code.google.com by azheng...@gmail.com on 21 Feb 2011 at 10:07

Attachments:

GoogleCodeExporter commented 9 years ago
    @Test
    public void testMapper() {
        UserInfo user = userInfoDao.getById(10L);
        System.out.println(user.getFirstName());
    }

[Result:]

org.mybatis.spring.MyBatisSystemException: nested exception is 
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: XML 
fragments parsed from previous mappers does not contain value for 
UserInfo.columns
### The error may exist in file 
[D:\workspace\gmf\gmf\web\WEB-INF\classes\com\gm\security\model\mapper\UserInfoM
apper.xml]
### Cause: java.lang.IllegalArgumentException: XML fragments parsed from 
previous mappers does not contain value for UserInfo.columns
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:346)
    at $Proxy16.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:154)
    at com.gm.common.orm.mybatis.BaseEntityDao.getById(BaseEntityDao.java:44)
    at com.gm.common.orm.mybatis.BaseEntityDao.getById(BaseEntityDao.java:1)
    at com.gm.security.dao.test.DaoTestCase.testMapper(DaoTestCase.java:155)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: XML 
fragments parsed from previous mappers does not contain value for 
UserInfo.columns
### The error may exist in file 
[D:\workspace\gmf\gmf\web\WEB-INF\classes\com\gm\security\model\mapper\UserInfoM
apper.xml]
### Cause: java.lang.IllegalArgumentException: XML fragments parsed from 
previous mappers does not contain value for UserInfo.columns
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:77)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
    ... 33 more
Caused by: java.lang.IllegalArgumentException: XML fragments parsed from 
previous mappers does not contain value for UserInfo.columns
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:593)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler.handleNode(XMLStatementBuilder.java:155)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseDynamicTags(XMLStatementBuilder.java:85)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:43)
    at org.apache.ibatis.session.Configuration.parseStatementNodes(Configuration.java:513)
    at org.apache.ibatis.session.Configuration.buildStatementsForNamespace(Configuration.java:502)
    at org.apache.ibatis.session.Configuration.buildStatementsFromId(Configuration.java:467)
    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:391)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:74)
    ... 40 more

Original comment by azheng...@gmail.com on 21 Feb 2011 at 10:14

GoogleCodeExporter commented 9 years ago
Not sure if this should work. The namespace should not be repeated on 
statements so it should be:

<mapper namespace="UserInfo">
    <sql id="columns">
        ...

    <select id="getById" resultMap="RM.UserInfo">
        ...

The include just needs the namespace qualified name if it will be loaded from 
another xml file (this is not the case). So both these should work:

<include refid="UserInfo.columns" />

<include refid="columns" />

could you give it a try?

Original comment by eduardo.macarron on 21 Feb 2011 at 2:54

GoogleCodeExporter commented 9 years ago
And your namespace should be the same as your full qualified mapper name:
com.gm.security.model.UserInfo

<mapper namespace="com.gm.security.model.UserInfo">
    <sql id="columns">
        ...

    <select id="getById" resultMap="RMUserInfo">
        ...

Please fix your namespaces and statement names and try again.

Original comment by eduardo.macarron on 21 Feb 2011 at 9:44

GoogleCodeExporter commented 9 years ago
<mapper namespace="com.gm.security.model.UserInfo">
......
    <sql id="columns">
......
     <select id="getById" resultMap="RM.UserInfo">
......

3.0.3 is ok,  

3.0.4 is exception:

java.lang.IllegalArgumentException: XML fragments parsed from previous mappers 
does not contain value for com.gm.security.model.UserInfo.columns
    at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:593)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler.handleNode(XMLStatementBuilder.java:155)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseDynamicTags(XMLStatementBuilder.java:85)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:43)
    at org.apache.ibatis.session.Configuration.parseStatementNodes(Configuration.java:513)
    at org.apache.ibatis.session.Configuration.buildStatementsForNamespace(Configuration.java:502)
    at org.apache.ibatis.session.Configuration.buildStatementsFromId(Configuration.java:467)
    at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:391)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:74)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
    at $Proxy8.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:154)
    at com.gm.common.orm.mybatis.BaseEntityDao.pageQuery(BaseEntityDao.java:102)
    at com.gm.common.orm.mybatis.BaseEntityDao.findPage(BaseEntityDao.java:96)
    at com.gm.common.service.BaseManager.findPage(BaseManager.java:53)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
......

Original comment by azheng...@gmail.com on 22 Feb 2011 at 1:44

GoogleCodeExporter commented 9 years ago
<mapper namespace="com.gm.security.model.UserInfo">
...... 
   <sql id="columns">
......
   <select id="getById" resultMap="RM.UserInfo">
    SELECT 
        <include refid="columns" />//3.0.3 is ok
        //or <include refid="com.gm.security.model.UserInfo.columns" />
        //I've tried all possible, still has problems in 3.0.4

Original comment by azheng...@gmail.com on 22 Feb 2011 at 1:53

GoogleCodeExporter commented 9 years ago
Just a final test. Could you rename RM.UserInfo to RM_UserInfo?

Original comment by eduardo.macarron on 22 Feb 2011 at 9:14

GoogleCodeExporter commented 9 years ago
Hi again, I have just tried it with 3.0.5 and it works. 

When RM.UserInfo is used "RM" mybatis believes that RM is a namespace. But it 
still works. 

Could you please try with the .zip I attached and try to reproduce your fail?

Original comment by eduardo.macarron on 22 Feb 2011 at 6:07

Attachments:

GoogleCodeExporter commented 9 years ago
In your last stacktrace I see you are using MyBatis-Spring. There is a solved 
issue with includes. Could you also try with mybatis-spring-1.0.1-SNAPSHOT that 
you will find on downloads?

Original comment by eduardo.macarron on 22 Feb 2011 at 6:09

GoogleCodeExporter commented 9 years ago
Thanks your exemple , run a success 

I changed "RM.UserInfo" to "RM_UserInfo" , used mybatis-3.0.4 and 
mybatis-spring-1.0.1-SNAPSHOT ,but the problem is still.

org.mybatis.spring.MyBatisSystemException: nested exception is 
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped 
Statements collection does not contain value for 
com.gm.security.model.UserInfo.getById
### The error may exist in file 
[D:\workspace\gmf\gmf\web\WEB-INF\classes\com\gm\security\model\mapper\UserInfoM
apper.xml]
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection 
does not contain value for com.gm.security.model.UserInfo.getById
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:346)
    at $Proxy16.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:154)
    at com.gm.common.orm.mybatis.BaseEntityDao.getById(BaseEntityDao.java:45)
    at com.gm.common.orm.mybatis.BaseEntityDao.getById(BaseEntityDao.java:1)
    at com.gm.security.dao.test.UserInfoDaoTest.testMapper(UserInfoDaoTest.java:151)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    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.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped 
Statements collection does not contain value for 
com.gm.security.model.UserInfo.getById
### The error may exist in file 
[D:\workspace\gmf\gmf\web\WEB-INF\classes\com\gm\security\model\mapper\UserInfoM
apper.xml]
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection 
does not contain value for com.gm.security.model.UserInfo.getById
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:77)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:69)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
    ... 33 more
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection 
does not contain value for com.gm.security.model.UserInfo.getById
    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.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:74)
    ... 40 more

Original comment by azheng...@gmail.com on 25 Feb 2011 at 3:46

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I found out what caused the error:

[my spring sqlSessionFactory bean config:]
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!--<property name="configLocation" value="config/db/mybatis-config.xml"></property>-->
    <property name="mapperLocations" value="classpath*:/com/gm/**/mapper/**/*Mapper.xml" />
</bean>

I did not use configLocation to load mappers,
I used mapperLocations to do it.

When I use 
<property name="configLocation" value="config/db/mybatis-config.xml"></property>
to load mappers in mybatis-config.xml, it is ok.

I think errors caused by SqlSessionFactoryBean use mapperLocations to load 
mappers.

Original comment by azheng...@gmail.com on 25 Feb 2011 at 4:08

Attachments:

GoogleCodeExporter commented 9 years ago
I thought that issue was solved in mybatis-spring-1.0.1.... 

Could you try it with mybatis-3.0.5-SNAPSHOT and mybatis-spring-1.0.1-SNAPSHOT 
to see if your issue is already solved in trunk?

Original comment by eduardo.macarron on 25 Feb 2011 at 5:35

GoogleCodeExporter commented 9 years ago
I did a fast test with Spring 1.0.1 and MyBatis 3.0.5 and worked for me... 
again :) I was only able to reproduce the error if the expression in 
mapperLocations is wrong and it does not find any mapper. 

Are you sure the expression com/gm/**/mapper/**/*Mapper.xml is picking any 
mapper?

Set logging to debug and you should see something like this:
Property 'configLocation' not specified, using default MyBatis Configuration
Parsed mapper file: 'file 
[/home/eduardo/workspace/mybatis-spring/target/test-classes/org/mybatis/spring/u
serinfo/UserInfoMapper.xml]'

can you see this in your log?

BTW make sure you are using 3.0.5-SNAPSHOT and 1.0.1-SNAPSHOT.

Original comment by eduardo.macarron on 25 Feb 2011 at 5:57

Attachments:

GoogleCodeExporter commented 9 years ago
Oh, use mybatis-3.0.5-SNAPSHOT and mybatis-spring-1.0.1-SNAPSHOT, it's be 
Resolved.

Since the upgrade to 3.0.4, this problem affects my whole week.

Thanks. Great!  I can rest assured that the use of subsequent versions of 
mybatis.

Original comment by azheng...@gmail.com on 26 Feb 2011 at 12:55

GoogleCodeExporter commented 9 years ago
Good to hear that! Thanks a lot for your time and help.

Original comment by eduardo.macarron on 26 Feb 2011 at 6:49

GoogleCodeExporter commented 9 years ago
The namespace should  be same in the following files:
1. Mapper file: 
<mapper namespace="org.jpadbf.spring3mybatis3.dao.DocumentDao"> 
    <select id="retrieve" resultType="Document">
        select * from tbl_documents
    </select>
 </mapper>

Namespace here is select id="retrieve"

2. 2nd is the interface here which is used in the 3rd point.

public interface DocumentDao {

    public List<Document> retrieve();

Here the namespace should be same as "retrieve".

3. public class DocumentManager {
    private DocumentDao documentDao;

    public List<Document> retrieve() {
        return documentDao.retrieve();
    }

Here also the name is same as "retrieve".

Rest any entry can have different names.

Original comment by angadpau...@gmail.com on 27 Jan 2012 at 8:50

GoogleCodeExporter commented 9 years ago
Also refer to the link which gives basic overview of the concept:
http://blog.idleworx.com/2011/09/mybatis-dao-example-code-tutorial.html

Original comment by angadpau...@gmail.com on 27 Jan 2012 at 8:51