文章目录
- 报错: There is no getter for property named 'tableName' in 'class java.lang.String'
- 报错: 元素类型为 "mapper" 的内容必须匹配 "(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*)+"。
- 报错:Could not set parameters for mapping: ParameterMapping{property='user.sex' } *** Cause: java.sql.SQLException: 无效的列类型: 1111
- 报错: Cause: java.sql.SQLSyntaxErrorException: ORA-01747: user.table.column, table.column 或列说明无效
- 报错:Result Maps collection already contains value for com.baiwang.cloud.mapper.skdata.PjFpmxMapper.BaseResultMap
- 报错:Cause: java.sql.SQLSyntaxErrorException: ORA-00971: 缺失 SET 关键字
- 报错:java.lang.NumberFormatException: empty String
- 报错:Caused by: java.text.ParseException: Failed to parse date ["']: (java.lang.NumberFormatException)
- 报错:Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符 (重)
- 报错:No function matches the given name and argument types. You might need to add explicit type casts.
- 报错:nested exception is org.apache.ibatis.binding.BindingException: Parameter 'array' not found.
- 报错:Could not find SQL statement to include with refid 'com.test.User.CustomResultMap'
- 报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.queryList
- 报错: bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column "user_type" does not exist
- mybatis执行到prepare语句就不走了,貌似卡死了。
报错: There is no getter for property named ‘tableName’ in ‘class java.lang.String’
原因:mybatis 传入string参数的时候 默认不会自动匹配上 需要添加@Param注解,例如:
public List<UserBean> forupdateTable(@Param(value="tableName") String tableName);
类似的报错还有:
There is no getter for property named ‘companyId’ in ‘class java.lang.Long’
处理方案一样。
这里要清楚getter
属性名大小写,也必须一致,否则也会报这个问题。
报错: 元素类型为 “mapper” 的内容必须匹配 “(cache-ref|cache|resultMap*|parameterMap*|sql*|insert*|update*|delete*|select*)+”。
这个错比较好找,一般是xml文文档不符合格式,例如我随便写些非标签内容,如adfasdfasdf 就会报这个错。
报错:Could not set parameters for mapping: ParameterMapping{property=‘user.sex’ } *** Cause: java.sql.SQLException: 无效的列类型: 1111
无效的列类型,后来发现是字段名写错了,如下应该是user.age,但是用的是user.sex:
<if test="user.sex!= null">
age = #{user.age},
</if>
报错: Cause: java.sql.SQLSyntaxErrorException: ORA-01747: user.table.column, table.column 或列说明无效
这说明一般是表的字段名写错了,例如表字段该是id,但是我写成了user.id:
<update id="updateUser" parameterType="UserBean">
update t_user
<trim prefix="set" suffixOverrides=",">
<if test="user.name != null">
name = #{user.name},
</if>
</trim>
WHERE user.id=#{user.id}
</update>
报错:Result Maps collection already contains value for com.baiwang.cloud.mapper.skdata.PjFpmxMapper.BaseResultMap
报这个错说明resultMap重复了。
排查过程
第一步:
排查同xml文件中是否有resultMap id重复的情况。如果重复,肯定是会报这个错的。
经查,没有重复id,那么为什么还会报这个错呢?
第二步:
除了同文件中id会重复之外,还有一种可能就是命名空间写错了,造成的id重复。
一般出现在拷贝mapper.xml的时候,忘记改namespace,造成namespace在多个文件中有重复的。例如:
<mapper namespace="com.abc.mapper.UserMapper">
<resultMap id="BaseResultMap" type="com.abc.model.*">
修改为正确的namespace,问题解决。
报错:Cause: java.sql.SQLSyntaxErrorException: ORA-00971: 缺失 SET 关键字
出现这个问题一般是
模块的值为空。
可能所有字段都为空。
也有可能是实体类传错了,属性名都不对,造成没有任何值传入到set。
报错:java.lang.NumberFormatException: empty String
是空字符串问题。 转换为decimal的时候会报错。 后台为decimal,json入参为""就会报这个错。
报错:Caused by: java.text.ParseException: Failed to parse date ["']: (java.lang.NumberFormatException)
还是空字符串的问题。 后台为date,json入参为"" 就会报这个错。 如果是null就没事。
报错:Cause: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符 (重)
这个一般是语句末尾加了分号。
在mybatis中末尾是不需要加分号的。
这种错误一定要避免,因为真的很low很低级。
报错:No function matches the given name and argument types. You might need to add explicit type casts.
表示语法有问题,范围比较大。
例如:
少了and
sum()函数用错了。
sum(a,b) 这是错的,谁教我这种用法的? 但代码中真写出来了,醉了。
sum(a+b) 这才是对的。
报错:nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘array’ not found.
一般用在foreach语句中,collection的名字写错了,就会报这个错。
报错:Could not find SQL statement to include with refid ‘com.test.User.CustomResultMap’
一看这个refid,就知道是引用的sql没找到。
看下<include>
标签中的refid,在<sql>
标签中是否存在。
报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.test.queryList
说明Mapper中的方法 和 Mapper.xml 的方法不对应。
例如:
Mapper中方法名为 findList
Mapper.xml中的方法为 queryList
方法名不对应就会出这个错。
报错: bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: column “user_type” does not exist
这个再简单不过了。
一般是select语句中的字段不存在。
mybatis执行到prepare语句就不走了,貌似卡死了。
这个现象比较奇特,说报错也不报错,就是不动,真是怪了啊。
一般是开发阶段,单条件查询语句,如果mapper语句写错了,就可能会有这个问题。
例如: 我的需求是根据username查询list,看下mapper.xml:
<if test="id != null and id != '' " >
and id = #{id}
</if>
<if test="id != null and username != '' " >
and username = #{username}
</if>
发现问题了吗?
username字段,test的条件写错了,写成了id,那么就相当于没有任何条件,几百万的数据,当然卡死了。