ORACLE 12C 插入数据遇到 Error getting generated key or setting result to parameter object错误
生活随笔
收集整理的這篇文章主要介紹了
ORACLE 12C 插入数据遇到 Error getting generated key or setting result to parameter object错误
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天用springboot和oracle的時候遇到以前的老項目保存數據的時候顯示報錯
Error getting generated key or setting result to parameter object根據這句話的字面理解意思就是??獲取生成的鍵或將結果設置為參數對象時出錯 ?
看了下網上的解決方法主要是這樣
第一種方式:
將useGeneratedKeys="true" 改為 useGeneratedKeys="false",或者將useGeneratedKeys="true"和keyProperty="id"直接刪除看了一下這種方式不適合我 、我沒有編寫xml文件
第二種方式:
Mybatis版本低的原因造成的、需要配置更搞得版本--我也忽略了
第三種方式:
設置@Options(useGeneratedKeys=true,keyProperty=“id”)主鍵
useGeneratedKeys=true表示使用數據庫自動增長的主鍵,
keyColumn用于指定數據庫table中的主鍵,
keyProperty用于指定傳入對象的成員變量。設置是否使用JDBC的getGenereatedKeys()方法獲取主鍵并賦值到keyProperty設置的對象的屬性中,
也就是就是把自增長的主鍵值賦值給對象相應的屬性。也不適合我、因為我沒有編寫xml和mapper、用的mybatis-plus底層提供了這些方法
最終解決方法:
1)在MybatisPlusConfig配置文件中加入OracleKeyGenerator的bean配置,讓mp支持oracle主鍵策略。
package io.renren.config;import com.baomidou.mybatisplus.incrementer.OracleKeyGenerator; import com.baomidou.mybatisplus.plugins.PaginationInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** mybatis-plus配置** @author lyy * @since 2021-9-17*/ @Configuration public class MybatisPlusConfig {/*** 分頁插件*/@Beanpublic PaginationInterceptor paginationInterceptor() {return new PaginationInterceptor();}/*** Sequence主鍵自增*/@Beanpublic OracleKeyGenerator oracleKeyGenerator() {return new OracleKeyGenerator();} }在每一個實體類Id屬性上添加
@TableId(value = “id”, type = IdType.AUTO) private Long id;完美解決。。。。。。。。。
總結
以上是生活随笔為你收集整理的ORACLE 12C 插入数据遇到 Error getting generated key or setting result to parameter object错误的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: junit 单元测试报错java.lan
- 下一篇: 730阵列卡支持多大硬盘_华为1000多