Reputation: 83
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.
Upvotes: 1
Views: 16864
Reputation: 83
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.
Upvotes: 5