wild84 2017-08-14 04:15 采纳率: 80%
浏览 1574
已采纳

oracle设置自动增长id,mybatis如何插入数据?

我的mybatis的xml mapper文件语句如下:

 <insert id="insertFlights" parameterType="com.entity.Flights" useGeneratedKeys="true" keyProperty="id">
        insert into FLIGHTS(ID,FLIGHT_CODE,FLIGHT_DATE,AIRLINE,TYPE,TAKE_AIRPORT_ID,LANDING_AIRPORT_ID,TAKE_TIME,LANDING_TIME,FLIGHT_TIME,STOP_AIRPORT,REFERENCE_PRICE) 
        values(#{id},#{flightCode},#{flightDate},#{airline},#{type},#{takeAirportId},#{landingAirportId},#{takeTime},#{landingTime},#{flightTime},#{stopAirport},#{referencePrice})
    </insert>

报的异常如下:

 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='id', mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 无效的列类型: 1111

如果我把xml mapper里的语句去掉id字段;则报异常如下:

 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column #1 from result set.  Cause: java.sql.SQLException: 请求的转换无效

请问应该怎么处理?

  • 写回答

3条回答 默认 最新

  • NightGone 2017-08-14 09:50
    关注

    你的语法有问题,既然你设置了数据库自增长,成功返回数据ID,那么为什么还要添加ID属性?参考:
    insert into FLIGHTS(
    FLIGHT_CODE,FLIGHT_DATE,AIRLINE,TYPE,TAKE_AIRPORT_ID,LANDING_AIRPORT_ID,TAKE_TIME,LANDING_TIME,FLIGHT_TIME,STOP_AIRPORT,REFERENCE_PRICE)
    values(
    #{flightCode},#{flightDate},#{airline},#{type},#{takeAirportId},#{landingAirportId},#{takeTime},#{landingTime},#{flightTime},#{stopAirport},#{referencePrice})

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究
  • ¥30 软件自定义无线电该怎样使用