Springboot开发中遇到的问题01---java.lang.IllegalArgumentException: argument type mismatch

场景:springboot+mybatisplus   在数据同步时新增记录

报错:java.lang.IllegalArgumentException: argument type mismatch


大致看出是mybatis 映射字段的时候出错了 。第一反应就是检查字段类型,检查字段有没有写错,回头对比了实体字段还有sql实在没发现问题。找不到出路的时候,想到在ibatis的setBeanProperty方法打了断点,检查字段发现id值是null  ,猜想就是空值导致的,我测试插入一条id不为null的 ,就不报错了,就此确认是字段的空值导致的,但我们平常新增时实体类对象的字段时总避免不了null的出现。这时想起来我们在配置mybatisplus的时候有一条配置:mybatis-plus.global-config.id-type  当时配置的时候设置了2,就是做非空判断的,我们把它改成0   ,再次运行原来的程序 就不在报错了。



阅读更多

argument type mismatch

12-06

错误信息:rnorg.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.chinasei.hibernate.model.SchoolMaster.schoolIDrn at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:128)rn at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:227)rn at org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:3610)rn at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)rn at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:144)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)rn at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)rn at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)rn at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)rn at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:563)rn at org.hibernate.impl.SessionImpl.save(SessionImpl.java:551)rn at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)rn at com.chinasei.hibernate.dao.SchoolMasterDAO.save(SchoolMasterDAO.java:21)rn at org.apache.jsp.School_jsp._jspService(School_jsp.java:75)rn at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)rn at java.lang.Thread.run(Unknown Source)rnCaused by: java.lang.IllegalArgumentException: argument type mismatchrn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)rn ... 32 morern2013-12-6 13:47:07 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet jsp threw exceptionrnjava.lang.IllegalArgumentException: argument type mismatchrnrnrnSchoolMasterDAO.java如下:rnpackage com.chinasei.hibernate.dao;rnimport java.util.List;rnrnimport org.apache.commons.logging.Log;rnimport org.apache.commons.logging.LogFactory;rnimport org.hibernate.Session;rnimport org.hibernate.Transaction;rnimport org.hibernate.criterion.Example;rnrnimport com.chinasei.hibernate.model.SchoolMaster;rnrnpublic class SchoolMasterDAO extends BaseHibernateDAOrn private static final Log log = LogFactory.getLog(SchoolMasterDAO.class);rn rn public void save(SchoolMaster transientInstance) rn log.debug("saving Students instance");rn Session session = getSession();rn Transaction tx = null;rn tryrn tx = session.beginTransaction();rn session.save(transientInstance);rn tx.commit();rn log.debug("save successful");rn catch(RuntimeException re)rn log.error("save failed",re);rn if(tx!=null)rn tx.rollback();rn rn re.printStackTrace();rn throw re;rn finallyrn session.close();rn rn rn rn public List findByExample(SchoolMaster instance) rn log.debug("finding Course instance by example");rn try rn List results = getSession().createCriteria(rn "com.chinasei.hibernate.dao.Course").add(rn Example.create(instance)).list();rn log.debug("find by example successful, result size: "rn + results.size());rn return results;rn catch (RuntimeException re) rn log.error("find by example failed", re);rn throw re;rn rn rnrnrnSchoolMaster.hbm.xml如下:rnrnrn rn rn rn rn rn rn rn rn rnrnrn rn rn rn schoolrn rn rn rn rn rn rnrnrnrnrnSchoolMaster.java如下:rnpackage com.chinasei.hibernate.model;rnpublic class SchoolMaster implements java.io.Serializablern rn public void setSchoolID(int schoolID) rn this.schoolID = schoolID;rn rnrn public long getSchoolID() rn return schoolID;rn rn rn public School getSchool() rn return school;rn rn public void setSchool(School school) rn this.school = school;rn rn rn rn public String getMasterName() rn return masterName;rn rn public void setMasterName(String masterName) rn this.masterName = masterName;rn rn rn private int schoolID;rn private String masterName;rn private School school;rn rnrnrnSchool.java如下:rnpackage com.chinasei.hibernate.model;rnrnpublic class School implements java.io.Serializablernrn rn rn public void setSchoolID(int schoolID) rn this.schoolID = schoolID;rn rnrn public long getSchoolID() rn return schoolID;rn rn rn public String getSchoolName() rn return schoolName;rn rn public void setSchoolName(String schoolName) rn this.schoolName = schoolName;rn rn public String getSchoolAddress() rn return schoolAddress;rn rn public void setSchoolAddress(String schoolAddress) rn this.schoolAddress = schoolAddress;rn rn private int schoolID;rn private String schoolName;rn private String schoolAddress;rn rnrn

没有更多推荐了,返回首页