0

前两天写了一段访问数据库的程序,运行良好。它包含一些关于以 TIME 作为参数搜索数据的操作。在 db 中,在我的例子中是 pgsql,它是时间戳。当我使用 MyBatis 时,我查看了 MyBatis 网站,我特别记得它说 MyBatis 会将 java.util.Date AND Calendar 转换为时间戳,并且由于 Calendar 很容易计算,所以我选择了它。然后大约 3 小时前,我的程序在已经将 20k 行数据写入我的数据库后崩溃了。错误信息是这样的:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='calendar', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.GregorianCalendar. Use setObject() with an explicit Types value to specify the type to use.

一开始我还以为是空指针的东西,所以很自然的从云服务器上拉出来,在本地运行调试,错误依旧。

Can't infer the SQL type to use for an instance of java.util.GregorianCalendar. Use setObject() with an explicit Types value to specify the type to use.

最后我意识到这是一个转换问题,MyBatis 拒绝使用 Calendar 作为时间戳的参数,至少在没有进一步配置的情况下是这样。然后我查看了MyBatis 网站,但没有提到 Calendar。

问题本身很简单地解决了,调用 getTime() 来获取替换所有日历的日期。但整件事仍然让我失望。有人记得 MyBatis 是否曾经能够投射日历吗?或者我是否需要就我的记忆障碍进行医疗护理?

4

1 回答 1

0

我放弃这个问题。但是,如果您出于同样的原因来到这里,请不要查看它,将日历更改为日期并继续前进。不值得考虑。

于 2021-11-23T07:16:38.477 回答