Jos*_*iaz 3 java spring oracle11g mybatis
我正在尝试执行此插入:
@Insert("" +
"insert into EXTRANET.EX_ENTIDAD (ENT_REFNUM, ENT_TIPO, REG_PUB_ID, OFIC_REG_ID, AREA_REG_ID, " +
"COD_LIBRO, NUM_PARTIDA, ANO_TITU, NUM_TITU, ENT_TRIGGER, TMSTMP_CREA, PRIORIDAD) " +
" values (EXTRANET.EX_ENTIDAD_SEQ.nextval, #{entTipo}, " +
"#{regPubId}, #{oficRegId}, #{areaRegId}, #{codLibro}, #{numPartida}, #{anoTitu}, " +
" #{numTitu}, 'SYNC', SYSDATE, #{prioridad})")
public int insertEntidades(Map map);
Run Code Online (Sandbox Code Playgroud)
但是如果某些 #{param} 是 NULL 我得到它错误:
引起:org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType NULL 。尝试为此参数设置不同的 JdbcType 或不同的 jdbcTypeForNull
我正在搜索一些解决方案并阅读我必须配置一个属性:jdbcTypeForNull
然后我在 Spring 中更新我的配置:
@Bean
public SqlSessionFactoryBean sqlSessionFactory() throws Exception,Throwable {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(getDataSource());
//sessionFactory.setConfigLocation( new ClassPathResource("gob.pe.sunarp.extranet.config.config.xml"));
sessionFactory.setTypeAliasesPackage("gob.pe.sunarp.extranet.dao.beans");
final Properties sqlSessionFactoryProperties = new Properties();
sqlSessionFactoryProperties.put("jdbcTypeForNull", "NULL");
sessionFactory.setConfigurationProperties(sqlSessionFactoryProperties );
return sessionFactory;
}
Run Code Online (Sandbox Code Playgroud)
但错误仍在继续。
我找到了很多 xml 解决方案,但我只使用 java 接口。
关于这个错误的一些想法?
如果 null 作为值传递,则 JDBC 需要所有可空列的 JDBC 类型。您可以通过阅读 PreparedStatement.setNull() 方法的 JavaDocs 自行调查。
您是否为您的参数设置了 jdbcType?例如:
#{property,javaType=int,jdbcType=NUMERIC}
Run Code Online (Sandbox Code Playgroud)
如文档中所示,设置 jdbcTypeForNull 可能不适用于您的驱动程序。
当没有为参数提供特定的 JDBC 类型时,为空值指定 JDBC 类型。一些驱动程序需要指定列 JDBC 类型,但其他驱动程序使用通用值,如 NULL、VARCHAR 或 OTHER。
| 归档时间: |
|
| 查看次数: |
13376 次 |
| 最近记录: |