Tag Archives: MyBatis learns error sets

Build a mybatis and it will appear session.selectOne Method error

Error:

org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.   Cause: java.lang. IllegalArgumentException: Mapped Statements collection does not contain value for com.helloword.mapper.UserMapper.xml
### Cause: java.lang. IllegalArgumentException: Mapped Statements collection does not contain value for com.helloword.mapper.UserMapper.xml
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:71)
at test.Test.main(Test.java:43)
Caused by: java.lang. IllegalArgumentException: Mapped Statements collection does not contain value for com.helloword.mapper.UserMapper.xml
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:888)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:721)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:714)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
… 4 more

Solution.

See the error message, guess that it may be because there is a problem with the configuration file, first see if the <mapper> configuration in mybatis-config.xml is correct, see if there is no problem with the <mapper> configuration see if the path of namespace in UserMapper.xml is correct, check if there is no problem with UerMapper. xml is in the package of com.helloword.mapper, but this package is empty. Move the mapping file of UserMapper.xml to the package of entity class, and modify the configuration in one and two. After testing, the above error is still reported.

New error message

org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/helloworld/model/UserMapper.xml
### Cause: org.apache.ibatis.builder. BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io. IOException: Could not find resource com/helloworld/model/UserMapper.xml
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:52)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:36)
at test.Test.<clinit>(Test.java:30)
Caused by: org.apache.ibatis.builder. BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io. IOException: Could not find resource com/helloworld/model/UserMapper.xml
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:50)
… 2 more
Caused by: java.io. IOException: Could not find resource com/helloworld/model/UserMapper.xml
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114)
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:371)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
… 4 more
Exception in thread “main” java.lang.NullPointerException
at test.Test.main(Test.java:41)

The error was: Problem creating SqlSession and reported a null pointer error for the main method. Solution: I was careless and wrote a wrong letter in the <mapper> configuration path of mybatis configuration file