MyBatis Partial version exception invalid comparison:java.util.Date and java.lang.String

Source: Internet
Author: User

Critical: Servlet.service () for Servlets [spring] in context with path [] threw exception [Request processing failed; nested EXCE Ption is org.mybatis.spring.MyBatisSystemException:nested exception is Org.apache.ibatis.exceptions.PersistenceException:

# # # Error querying database. Cause:java.lang.IllegalArgumentException:invalid Comparison:java.util.Date and Java.lang.String
# # # Cause:java.lang.IllegalArgumentException:invalid Comparison:java.util.Date and java.lang.String] with root cause< /c0>

Java.lang.IllegalArgumentException:invalid Comparison:java.util.Date and Java.lang.String
At Org.apache.ibatis.ognl.OgnlOps.compareWithConversion (ognlops.java:93)
At Org.apache.ibatis.ognl.OgnlOps.isEqual (ognlops.java:143)
At Org.apache.ibatis.ognl.OgnlOps.equal (ognlops.java:802)
At Org.apache.ibatis.ognl.ASTNotEq.getValueBody (astnoteq.java:53)
At Org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody (simplenode.java:212)
At Org.apache.ibatis.ognl.SimpleNode.getValue (simplenode.java:258)
At Org.apache.ibatis.ognl.ASTAnd.getValueBody (astand.java:61)
At Org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody (simplenode.java:212)
。。。。

On the surface is because the type does not meet, but think, the date type corresponds to the MySQL datetime, as well as mapper in the Jdbctype all no problem ah. and the exact same thing is perfectly normal in the original project. Since it's all the same code, look for the two projects.

The first is a different version of the MySQL jar. It is not valid to replace the original project version. Then the MyBatis jar version is not the same, replaced by the original project version of the problem solved!

The original project was configured with mybatis-3.2.8, and I was using mybatis-3.3.1 in my test project. I later found it on the internet to find out why:

It turns out that this is a bug when comparing time parameters in MyBatis 3.3.0. If you compare an incoming time type argument to an empty string, the exception is thrown. So in the above code to go to the judgment, only the non-null judgment is normal

For example: in the Xxmapper.xml

<update id= "Updaccount" parametertype= "Com.isoftstone.ci.user.domain.Account" >
Update Usr_account Set
<trim suffixoverrides= "," >
<if test= "Sysaccounttype! = null" >
Sys_account_type=#{sysaccounttype},
</if>
<if test= "realnameauthed! = null" >
Real_name_authed=#{realnameauthed},
</if>
<if test= "Lastloginat! = null and Lastloginat! =" ">
Last_login_at=#{lastloginat}
</if>

</trim>
Where Id=#{id}
</update>

Replace the code with the following code (remove the comparison between time and empty string Lastloginat! = ")

<update id= "Updaccount" parametertype= "Com.isoftstone.ci.user.domain.Account" >
Update Usr_account Set
<trim suffixoverrides= "," >
<if test= "Sysaccounttype! = null" >
Sys_account_type=#{sysaccounttype},
</if>
<if test= "realnameauthed! = null" >
Real_name_authed=#{realnameauthed},
</if>
<if test= "Lastloginat! = null" >
Last_login_at=#{lastloginat}
</if>

</trim>
Where Id=#{id}
</update>

MyBatis Partial version exception invalid comparison:java.util.Date and java.lang.String

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.