Mybatis踩坑之一天
background:
对接AML系统,日间实时需要送交易对手要素过去(目前主要是交易对手全名),夜间需要将历史交易送AML进行回溯,交互方式是文件。文件要素为日期、对手类型、对手名、交易流水之类。
设置对送AML的文件设计表机构,除了交易明细的机构,再设计了一个记录每日发送情况的表,主键为日期,记录对接的状态。
主键日期设置为整型(坑的开始),在POJO里设置为int类型,是MYSQL中的类型选用了int类型(smallint无法支持99991231),整型比较较快,比string好一些。
另外用了4个时间字段,记录文件的创建上传时间。
然后应用mybatis的 selectByPrimaryKey 传入主键(不论是string还是int)都会提示无法org.apache.ibatis.type.TypeException: Could not set parameters for mapping,报错误导严重:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='crtStTime', mode=IN, javaType=class java.util.Date, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #5 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
另外一个date字段,尝试在xml中进行指定JdbcType类型是否不正确,无法支持null值的反向,一直在想是否另外一个字段有问题,AI问了好久,都无法定位问题。
最后发现是mybatis对int无法支持,需要用Integer 进行对应。