簡體   English   中英

MyBatis 是否曾經能夠投射 java 日歷?

[英]Has MyBatis ever been able to cast java Calendar?

前兩天寫了一段訪問數據庫的程序,運行良好。 它包含一些關於以 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.

首先我以為是 null 指針的東西,所以我很自然地將它從雲服務器中拉出來並在本地運行並調試,錯誤仍然存在。

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 是否曾經能夠投射日歷嗎? 或者我是否需要就我的 memory 損傷進行醫療護理?

我放棄這個問題。 但是,如果您出於同樣的原因來到這里,請不要查看它,將日歷更改為日期並繼續前進。 不值得考慮。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM