Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: 不支持的特性


mybatis插入數據時報錯:

Cause: org.apache.ibatis.executor.ExecutorException: Error getting generated key or setting result to parameter object. Cause: java.sql.SQLException: 不支持的特性
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)

原因:加了如下標紅的設置(useGeneratedKeys="true"把新增加的主鍵賦值到自己定義的keyProperty(id)中)

<insert id="insert" parameterType="com.vimtech.bms.business.domain.monitor.finan.AssetsVisitReportWithBLOBs" useGeneratedKeys="true" keyProperty="serialid">

解決方法一:沒什么用的話,刪除標紅的即可;

解決方法二:用selectKey先查下自增的主鍵ID值然后賦給相應的主鍵ID即可

oracle的寫法(查序列的下一個值然后賦值):

<selectKey resultType="java.lang.Long" order="BEFORE" keyProperty="###">
  SELECT SEQ_ASSETS_VISIT_REPORT.nextval AS ### FROM dual
</selectKey>

SQLServer的寫法

<selectKey resultType="java.lang.Integer" keyProperty="timelineConfigId">
  SELECT @@IDENTITY AS TIMELINE_CONFIG_ID
</selectKey>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM