赞
踩
我的一个表插入的时候是通过实时获取定义的序列(sequence)来拿到自增值的
sequence定义的内容如下
- -- Create sequence
- create sequence SEQ_IDS_FILE_LIST
- minvalue 1
- maxvalue 999999999999
- start with 49
- increment by 1
- cache 20;
mybatis的xml定义的插入语句如下
- <insert id="insertIdsFileList" parameterType="IdsFileList">
- <selectKey keyProperty="id" resultType="long" order="BEFORE">
- SELECT seq_ids_file_list.NEXTVAL as id FROM DUAL
- </selectKey>
- insert into ids_file_list
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="id != null">id,</if>
- <if test="projectId != null">project_id,</if>
- <if test="subSystem != null">sub_system,</if>
- <if test="devCode != null">dev_code,</if>
- <if test="name != null and name != ''">name,</if>
- <if test="code != null">code,</if>
- <if test="respUnit != null">resp_unit,</if>
- <if test="fileFormat != null">file_format,</if>
- <if test="cabin != null">cabin,</if>
- <if test="importTime != null">import_time,</if>
- <if test="changeTimes != null">change_times,</if>
- <if test="inPlace != null">in_place,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="id != null">#{id},</if>
- <if test="projectId != null">#{projectId},</if>
- <if test="subSystem != null">#{subSystem},</if>
- <if test="devCode != null">#{devCode},</if>
- <if test="name != null and name != ''">#{name},</if>
- <if test="code != null">#{code},</if>
- <if test="respUnit != null">#{respUnit},</if>
- <if test="fileFormat != null">#{fileFormat},</if>
- <if test="cabin != null">#{cabin},</if>
- <if test="importTime != null">#{importTime},</if>
- <if test="changeTimes != null">#{changeTimes},</if>
- <if test="inPlace != null">#{inPlace},</if>
- </trim>
- </insert>
表结构如下
- -- Create table
- create table IDS_FILE_LIST
- (
- ID VARCHAR2(20) not null,
- PROJECT_ID VARCHAR2(20),
- SUB_SYSTEM VARCHAR2(20),
- DEV_CODE VARCHAR2(64),
- NAME VARCHAR2(256) not null,
- CODE VARCHAR2(64),
- RESP_UNIT VARCHAR2(20),
- FILE_FORMAT VARCHAR2(20),
- CABIN VARCHAR2(20),
- IMPORT_TIME DATE,
- CHANGE_TIMES NUMBER(3),
- IN_PLACE NUMBER(1)
- )
- tablespace IDS
- pctfree 10
- pctused 40
- initrans 1
- maxtrans 255
- storage
- (
- initial 64
- next 1
- minextents 1
- maxextents unlimited
- );
- -- Add comments to the table
- comment on table IDS_FILE_LIST
- is 'IDS数据来源管理表';
- -- Add comments to the columns
- comment on column IDS_FILE_LIST.ID
- is '唯一标识';
- comment on column IDS_FILE_LIST.PROJECT_ID
- is '项目ID';
- comment on column IDS_FILE_LIST.SUB_SYSTEM
- is '分系统';
- comment on column IDS_FILE_LIST.DEV_CODE
- is '设备代号';
- comment on column IDS_FILE_LIST.NAME
- is '文件名称';
- comment on column IDS_FILE_LIST.CODE
- is '文件编号';
- comment on column IDS_FILE_LIST.RESP_UNIT
- is '责任单位';
- comment on column IDS_FILE_LIST.FILE_FORMAT
- is '文件形式';
- comment on column IDS_FILE_LIST.CABIN
- is '所属舱段';
- comment on column IDS_FILE_LIST.IMPORT_TIME
- is '导入时间';
- comment on column IDS_FILE_LIST.CHANGE_TIMES
- is '更改单次号';
- comment on column IDS_FILE_LIST.IN_PLACE
- is '正式文件是否到位';
- -- Create/Recreate primary, unique and foreign key constraints
- alter table IDS_FILE_LIST
- add constraint PK_IDS_FILE_LIST primary key (ID)
- using index
- tablespace IDS
- pctfree 10
- initrans 2
- maxtrans 255
- storage
- (
- initial 64K
- next 1M
- minextents 1
- maxextents unlimited
- );
- alter table IDS_FILE_LIST
- add constraint FK_IDS_FILE_LIST_REF_PROJ foreign key (PROJECT_ID)
- references IDS_PROJECT (ID);
注意:ID定义的是“VARCHAR2(20)”,类型是字符串
发现sequence获取的值是数字类型,所以需要做转换,否则报如下错误
-
- 23:34:58.388 [http-nio-80-exec-6] ERROR c.r.f.w.e.GlobalExceptionHandler - [notFount,64] - 运行时异常:
- org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.ruoyi.ids.domain.IdsFileList' with value '33' Cause: java.lang.IllegalArgumentException: argument type mismatch
- at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:92)
- at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440)
- at com.sun.proxy.$Proxy89.insert(Unknown Source)
- at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271)
- at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
- at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
- at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
- at com.sun.proxy.$Proxy134.insertIdsFileList(Unknown Source)
- at com.ruoyi.ids.service.impl.IdsFileListServiceImpl.insertIdsFileList(IdsFileListServiceImpl.java:57)
- at com.ruoyi.ids.controller.IdsFileListController.addSave(IdsFileListController.java:86)
- at com.ruoyi.ids.controller.IdsFileListController$$FastClassBySpringCGLIB$$49dd271.invoke(<generated>)
- at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
- at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:771)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
- at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
- at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
- at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
- at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
- at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
- at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor$1.proceed(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:82)
- at org.apache.shiro.authz.aop.AuthorizingMethodInterceptor.invoke(AuthorizingMethodInterceptor.java:39)
- at org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor.invoke(AopAllianceAnnotationsAuthorizingMethodInterceptor.java:115)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
- at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
- at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
- at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749)
- at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691)
- at com.ruoyi.ids.controller.IdsFileListController$$EnhancerBySpringCGLIB$$379e3d42.addSave(<generated>)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
- at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
- at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
- at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
- at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
- at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
- at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
- at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
- at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
- at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
- at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
- at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
- at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
- at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
- at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
- at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
- at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
- at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
- at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
- at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
- at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
- at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
- at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
- at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
- at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
- at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
- at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:450)
- at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
- at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
- at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
- at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)
- at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
- at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:124)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at com.ruoyi.common.xss.XssFilter.doFilter(XssFilter.java:62)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
- at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
- at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
- at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
- at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
- at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
- at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
- at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
- at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
- at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
- at java.lang.Thread.run(Thread.java:745)
- Caused by: org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.ruoyi.ids.domain.IdsFileList' with value '33' Cause: java.lang.IllegalArgumentException: argument type mismatch
- at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:90)
- at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processBefore(SelectKeyGenerator.java:47)
- at org.apache.ibatis.executor.statement.BaseStatementHandler.generateKeys(BaseStatementHandler.java:141)
- at org.apache.ibatis.executor.statement.BaseStatementHandler.<init>(BaseStatementHandler.java:63)
- at org.apache.ibatis.executor.statement.PreparedStatementHandler.<init>(PreparedStatementHandler.java:41)
- at org.apache.ibatis.executor.statement.RoutingStatementHandler.<init>(RoutingStatementHandler.java:46)
- at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:636)
- at org.apache.ibatis.executor.ReuseExecutor.doUpdate(ReuseExecutor.java:50)
- at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
- at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63)
- at com.sun.proxy.$Proxy159.update(Unknown Source)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
- at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:426)
- ... 115 common frames omitted
- Caused by: org.apache.ibatis.reflection.ReflectionException: Could not set property 'id' of 'class com.ruoyi.ids.domain.IdsFileList' with value '33' Cause: java.lang.IllegalArgumentException: argument type mismatch
- at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:185)
- at org.apache.ibatis.reflection.wrapper.BeanWrapper.set(BeanWrapper.java:59)
- at org.apache.ibatis.reflection.MetaObject.setValue(MetaObject.java:140)
- at org.apache.ibatis.executor.keygen.SelectKeyGenerator.setValue(SelectKeyGenerator.java:115)
- at org.apache.ibatis.executor.keygen.SelectKeyGenerator.processGeneratedKeys(SelectKeyGenerator.java:80)
- ... 137 common frames omitted
- Caused by: java.lang.IllegalArgumentException: argument type mismatch
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:498)
- at org.apache.ibatis.reflection.invoker.MethodInvoker.invoke(MethodInvoker.java:44)
- at org.apache.ibatis.reflection.wrapper.BeanWrapper.setBeanProperty(BeanWrapper.java:180)
- ... 141 common frames omitted
解决的办法有两种
1、把获取的id由数字改成字符串,
- <selectKey keyProperty="id" resultType="long" order="BEFORE">
- SELECT seq_ids_file_list.NEXTVAL as id FROM DUAL
- </selectKey>
改成
- <selectKey keyProperty="id" resultType="string" order="BEFORE">
- SELECT seq_ids_file_list.NEXTVAL as id FROM DUAL
- </selectKey>
2、把表结构的主键id改为数字类型
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。