Fork me on GitHub

Mybatis错误总结

   MyBatis是现在主流框架ssm的一部分,接下里我在学习过程中遇到的各种错误在此总结了一下

1
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=FindUserByUsername], {ExactMatcher:fDisplayName=FindUserByUsername(top.gclmit.test.JunitTest)], {LeadingIdentifierMatcher:fClassName=top.gclmit.test.JunitTest,fLeadingIdentifier=FindUserByUsername]] from org.junit.internal.requests.ClassRequest@579bb367

错误原因:在junit测试中忘记在测试单元上添加@Test

1
2
3
4
5
6
org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values('贱人','2017-10-10 10:39:10.119','hky','男')' at line 1
### The error may involve User.insertUser-Inline
### The error occurred while setting parameters
### SQL: insert into user (username,birthday,address,sex,) values(?,?,?,?)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') values('贱人','2017-10-10 10:39:10.119','hky','男')' at line 1

错误原因: 自己不小小心,再User.xml中的sql语句中多加了一个逗号

1
2
3
4
5
6
org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'birthdy' in 'class top.gclmit.pojo.User'
### The error may involve User.updateUserById-Inline
### The error occurred while setting parameters
### SQL: update user set username = ?,birthdy=?,address=?,sex=? where id=?
### Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'birthdy' in 'class top.gclmit.pojo.User'

错误原因: 实体类User中不存在birthdy。经检查发现变量birthday打错了.

1
2
3
4
org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in sqlmap/User.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias ''. Cause: java.lang.ClassNotFoundException: Cannot find class:

错误原因: User.xml文档中有个sql语句没写完。

1
2
3
4
5
6
org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user where id = 29' at line 1
### The error may involve User.deleteUserById-Inline
### The error occurred while setting parameters
### SQL: delete form user where id = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'user where id = 29' at line 1

错误原因: delete form user where id = ? sql语句书写错误,正确应为 delete from user where id = ?

1
org.apache.ibatis.binding.BindingException: Type interface top.gclmit.mapper.UserMapper is not known to the MapperRegistry.

错误原因: MapperRegistry找不到这个接口,经检查是sqlMapConfig.xml文件中的接口位置错误

1
2
3
4
5
6
7
org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'userId' of 'class top.gclmit.pojo.User' with value '1' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'userId' in 'class top.gclmit.pojo.User'
### The error may exist in top/gclmit/mapper/OrderMapper.xml
### The error may involve top.gclmit.mapper.OrderMapper.selectOrders
### The error occurred while handling results
### SQL: select o.id, o.user_id, o.number, o.createtime, u.username from orders o left join user u on o.user_id=u.id
### Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'userId' of 'class top.gclmit.pojo.User' with value '1' Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'userId' in 'class top.gclmit.pojo.User'

错误原因: 在User这个pojo中找不到userId这个属性

本文标题:Mybatis错误总结

文章作者:孤城落寞

发布时间:2018年01月23日 - 09:52:38

最后更新:2019年02月21日 - 22:01:02

原始链接:https://blog.gclmit.club/archives/b31ba208.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。



-------------本文结束 感谢您的阅读-------------
坚持原创技术分享,您的支持将鼓励我继续创作!