1
votes

I've got an error with date comparison in ibatis in Springboot 2.0 and I'm out of ideas.

My Mapper looks like this (using MySql):

@Select("select count(s.id,r.date) from eshrsys.score s join eshrsys.round on (s.round_id = r.id) where r.date > '#{date,jdbcType=DATE}'")
Integer getScoreCountFromDate(Date date);

I'm passing in a valid java.sql.date object that's not null. But I get this error referencing the date comparison:

2018-09-02 21:14:23.999 ERROR 5644 --- [nio-8088-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='date', mode=IN, javaType=class java.sql.Date, jdbcType=DATE, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType DATE . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).]

I've tried a number of different workarounds, from converting the input to a string before sending it in, to removing the single quotes, to playing with the jdbcType. Nothing has worked.

1
Try to change #{date,jdbcType=DATE} to ${date,jdbcType=DATE} - Alien
Well, it's a different error now 2018-09-02 22:12:34.905 ERROR 18832 --- [nio-8088-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'DATE' in 'class java.sql.Date'] - LeeRosenberg
So that link seems to suggest I go back to the #{} syntax. I tried a few other things, including changing the name of passed in variable (I thought maybe date was a special name I couldn't use). Still no luck. - LeeRosenberg
yeah..better to go with # only..good luck. - Alien

1 Answers

4
votes

I finally figured this out, it turned out to be a very different issue than I suspected. The simple fix to the error above is to remove the single quotes around '#{date,jdbcType=DATE}'.

I'd done that initially but was getting a MySQL syntax error 'near r.date', which I thought had to be related to my date comparison, but it wasn't! It was complaining about the r.date in the beginning in my 'count(s.id,r.date)' statement. Replacing that with 'count(*)' fixed that. And I was unblocked.