mybatis爆出constructor和getter异常的解决方法:

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_37961948/article/details/81482661

MyBatisSystemException:No constructor found Bean/POJO

mybatis框架使用无参构造器后使用setter将数据库返回的数据压入bean中,所以这个原因一般都是因为没有无参构造器,加上无参就可以解决了。

MybatisException:There is no getter for property named 'XXX' in

如果XXX是 字段名,很简单,一般都是大小写错误或者拼写错误,直接从bean中拷贝一份替换就可以了。

当然不排除确实没有getter的情况。(一般细心点都没这个问题)

今天我遇到的则更神奇一些,XXX竟然是我传入的model的类名:person。其实不难。

因为我们在xml里面使用了诸如:

<if test="person.id != null">    //报错:No getter of person,注意是首字母小写,我们的类名是Person
    body
</test>

那么问题也很好解决,

public updatePersonById(Person person);

//改成
public updatePersonById(@Param("person") Person person);

//这个“person”是由你的mapper中使用的名称决定。

 

展开阅读全文

No getter method for property异常

01-14

提示这个异常,但是我的FormBean里面确实写了这个方法,代码贴出来,大家帮忙看看吧!谢谢了rn[code=HTML]rn rn rn rn rn rn rn <%rn if(com.dgis.common.DgisAdmin.getHySession(request)!=null)rn if(com.dgis.common.DgisAdmin.getHySession(request).getHyid().equals("38620065011301315"))%>rn rn <% elseif(!"0".equals(com.dgis.common.DgisAdmin.getHySession(request).getQxlx()))%>rn 全选 rn <%rn %>rn 关键字: rn rn <%if(!"0".equals(com.dgis.common.DgisAdmin.getHySession(request).getQxlx()))%>rn rn <%%>rn rn rn rn rn rn rn rn <%if(!"0".equals(com.dgis.common.DgisAdmin.getHySession(request).getQxlx()))%><%%>rn rn rn rn rn rn rn rn rn <%=pagestr%>rn rn <%rn %>rn rn [/code]rn[code=Java]rnrnrnpublic class BztgAction extends Action rn public ActionForward execute(rn ActionMapping mapping,rn ActionForm form,rn HttpServletRequest request,rn HttpServletResponse response)rn BztgForm bztgForm = (BztgForm) form;rn if(!DgisAdmin.checkPrivilege(request))rn return mapping.findForward("noright");rn rn Session session=HibernateUtil.currentSession();rn Transaction tx=session.beginTransaction();rn HySession hysession;rn Query query=null;rn String sql;rn PageUtil page=new PageUtil();rn hysession = DgisAdmin.getHySession(request);rn if(bztgForm.getPage()==null)rn page.setCurrentPage(1);rn elsern page.setCurrentPage(Integer.parseInt(bztgForm.getPage()));rn rn bztgForm.setPage(String.valueOf(page.getCurrentPage()));rn String hyid = "";rn hyid = hysession.getHyid();rn sql="select bztgtemp.skid,bztgtemp.skname,bztgtemp.xfsj,bztgtemp.tgbz from Bztg bztgtemp where bztgtemp.bzhy.hyid='"+hyid+"'";rn query = session.createQuery(sql);rn page.setTotalRecord(query.list().size());rn if(page.getCurrentPage()<1)rn page.setPageSize(page.getTotalRecord());rn page.setCurrentPage(0);rn rn elsern page.resetPageSize();rn if(page.getCurrentPage()>page.getTotalPage())rn page.setCurrentPage(page.getTotalPage());rn rn if(page.getCurrentRecord1()<=0)rn query.setFirstResult(0);rn elsern query.setFirstResult(page.getCurrentRecord1()-1);rn rn query.setMaxResults(page.getPageSize());rn bztgForm.setBztglist(query.list());rn bztgForm.setPagestr(page.getPageStr("bztgForm"));rn System.out.println(bztgForm.getSkid());rn tx.commit();rn HibernateUtil.closeSession();rn return mapping.findForward("bztg");rn rnrn[/code]rn[code=Java]rnpublic class BztgForm extends ActionFormrn private static final long serialVersionUID = 1L;rn rn private List bztglist;rn rn private String skid;rn rn private String page;rn rn private String pagestr;rn rn private String hyid;rn rn private String skname;rnrn public String getHyid() rn return hyid;rn rnrn public void setHyid(String hyid) rn this.hyid = hyid;rn rnrn public String getSkname() rn return skname;rn rnrn public void setSkname(String skname) rn this.skname = skname;rn rnrn public List getBztglist() rn return bztglist;rn rnrn public void setBztglist(List bztglist) rn this.bztglist = bztglist;rn rnrn public String getSkid() rn return skid;rn rnrn public void setSkid(String skid) rn this.skid = skid;rn rnrnrn public String getPage() rn return page;rn rnrn public void setPage(String page) rn this.page = page;rn rnrn public String getPagestr() rn return pagestr;rn rnrn public void setPagestr(String pagestr) rn this.pagestr = pagestr;rn rnrn[/code] 论坛

HttpClient爆出peer not authenticated异常

12-29

如题,在eclipse里运行,不爆异常,单独打包成jar后命令行运行就爆这个异常了,特别费解。rnrn包括加X509Certificate都试过了不行。rnrn在eclipse下,加不加X509Certificate都正常。但是单独命令行就有问题。rnjava -Djava.ext.dirs=lib -jar anna-anjyo-1.0-SNAPSHOT.jarrnrnException in thread "main" javax.net.ssl.SSLPeerUnverifiedException: peer not aurnthenticatedrn at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.jarnva:421)rn at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.javrna:128)rn at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactrnory.java:397)rn at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnectrnion(DefaultClientConnectionOperator.java:148)rn at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.jarnva:149)rn at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPoolrnedConnAdapter.java:121)rn at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultrnRequestDirector.java:573)rn at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultReqrnuestDirector.java:425)rn at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClrnient.java:820)rn at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClrnient.java:754)rn at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClrnient.java:732)rn at com.anna.anjyo.Account.main(Account.java:52)rn 论坛

mybatis 报错 There is no getter for property named 'xxx' in 'xxx'

04-12

[code=text]Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'is_partner' in 'class com.xfj.base.bossapp.domain.SellerAgent'rn at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:333)rn at org.apache.ibatis.reflection.MetaClass.getGetInvoker(MetaClass.java:160)rn at org.apache.ibatis.reflection.wrapper.BeanWrapper.getBeanProperty(BeanWrapper.java:151)rn at org.apache.ibatis.reflection.wrapper.BeanWrapper.get(BeanWrapper.java:44)rn at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:123)rn at org.apache.ibatis.builder.xml.dynamic.DynamicContext$ContextMap.get(DynamicContext.java:89)rn at org.apache.ibatis.builder.xml.dynamic.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:107)rn at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)rn at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)rn at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)rn at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)rn at org.apache.ibatis.ognl.ASTNotEq.getValueBody(ASTNotEq.java:49)rn at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)rn at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)rn at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)rn at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)rn at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)rn at org.apache.ibatis.builder.xml.dynamic.OgnlCache.getValue(OgnlCache.java:42)rn at org.apache.ibatis.builder.xml.dynamic.ExpressionEvaluator.evaluateBoolean(ExpressionEvaluator.java:32)rn at org.apache.ibatis.builder.xml.dynamic.IfSqlNode.apply(IfSqlNode.java:30)rn at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:29)rn at org.apache.ibatis.builder.xml.dynamic.TrimSqlNode.apply(TrimSqlNode.java:42)rn at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:29)rn at org.apache.ibatis.builder.xml.dynamic.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37)rn at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:241)rn at org.apache.ibatis.executor.statement.BaseStatementHandler.(BaseStatementHandler.java:61)rn at org.apache.ibatis.executor.statement.PreparedStatementHandler.(PreparedStatementHandler.java:36)rn at org.apache.ibatis.executor.statement.RoutingStatementHandler.(RoutingStatementHandler.java:42)rn at org.apache.ibatis.session.Configuration.newStatementHandler(Configuration.java:348)rn at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:43)rn at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108)rn at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75)rn at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:355)rn ... 176 more[/code]rnrn找了好久都找不到什么问题,用的方法是用工具生成的update方法 论坛

IllegalArgumentException occurred calling getter 总有这个异常

09-14

javax.servlet.ServletException: IllegalArgumentException occurred calling getter of org.libo.db.Student.stuId; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.libo.db.Student.stuIdrn org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnrn原因 rnrnorg.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of org.libo.db.Student.stuId; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of org.libo.db.Student.stuIdrn org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:661)rn org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:413)rn org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:371)rn org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:658)rn org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:654)rn org.libo.db.StudentDAO.update(StudentDAO.java:50)rn org.libo.ui.action.MyActionAction.execute(MyActionAction.java:67)rn org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:106)rn org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rn org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)rn org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:709)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:802)rnrnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnpackage org.libo.db;rnrnimport java.util.HashSet;rnimport java.util.Set;rnrnimport org.apache.struts.validator.ValidatorActionForm;rnrnrnrn/**rn * Student generated by MyEclipse - Hibernate Toolsrn */rnrnpublic class Student extends ValidatorActionForm implements java.io.Serializable rnrnrn // Fields rnrn private Integer stuId;rn private String stuName;rn private String stuPwd;rnrn private Set courses = new HashSet();rnrn // Constructorsrnrn public Set getCourses() rn return courses;rn rnrnrn public void setCourses(Set courses) rn this.courses = courses;rn rnrnrn /** default constructor */rn public Student() rn rnrn rn /** full constructor */rn public Student(String stuName, String stuPwd) rn this.stuName = stuName;rn this.stuPwd = stuPwd;rn rnrn rn // Property accessorsrnrn public Integer getStuId() rn return this.stuId;rn rn rn public void setStuId(Integer stuId) rn this.stuId = stuId;rn rnrn public String getStuName() rn return this.stuName;rn rn rn public void setStuName(String stuName) rn this.stuName = stuName;rn rnrn public String getStuPwd() rn return this.stuPwd;rn rn rn public void setStuPwd(String stuPwd) rn this.stuPwd = stuPwd;rn rn rnrnrnrnrnrnrnrnrn 论坛

Hibernate异常:Unable to locate appropriate constructor on class

11-12

[code=Java]rn public List getCity() //方法rn // TODO Auto-generated method stubrn session = HibernateSessionFactory.getSession();rn List list = session.createQuery("select new com.snzo.dao.WorldOnlinePortCity(wp.id,wp.name) from WorldOnlinePortCity as wp").list(); //用过直接 new WorldOnlinePortCity(wp.id,wp.name)rn session.close();rn return list ;rn rnrn public static void main(String []args) 测试 rn List list = new City_Imp().getCity();rn for(Iterator it = list.iterator();it.hasNext();)rn WorldOnlinePortCity goods = (WorldOnlinePortCity)it.next();rn System.out.println(goods.getId());rn rn rn rn public class WorldOnlinePortCity implements java.io.Serializable //持久化类rnrn // Fieldsrnrn private Long id; rn private String name; rn private String des; rn private Set city; rn // Constructorsrnrn /** default constructor */rn public WorldOnlinePortCity() //默认构造rn rnrn /** minimal constructor */rn// public WorldOnlinePortCity(Long id) rn// this.id = id;rn// rnrn /** full constructor */rn public WorldOnlinePortCity(Long id, String name, String des,Set city) //构造函数rn this.id = id;rn this.name = name;rn this.des = des;rn this.city=city; //Set 类型 不写也试验过 报一样的错。rn 不管 怎么写 都这这样的错误 rn 错误:rnException in thread "main" org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.snzo.dao.WorldOnlinePortCity] [select new com.snzo.dao.WorldOnlinePortCity(wp.id,wp.name) from com.snzo.dao.WorldOnlinePortCity as wp]rn at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)rn at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:225)rn at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)rn at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)rn at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:75)rn at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:54)rn at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)rn at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)rn at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)rn at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)rn at com.snzo.bo.City_Imp.getCity(City_Imp.java:75)rn at com.snzo.bo.City_Imp.main(City_Imp.java:81)rnCaused by: Unable to locate appropriate constructor on class [com.snzo.dao.WorldOnlinePortCity]rn[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.snzo.dao.WorldOnlinePortCity]rn at org.hibernate.hql.ast.tree.ConstructorNode.resolveConstructor(ConstructorNode.java:122)rn at org.hibernate.hql.ast.tree.ConstructorNode.prepare(ConstructorNode.java:88)rn at org.hibernate.hql.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:837)rn at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1952)rn at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1821)rn at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1392)rn at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:553)rn at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)rn at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)rn at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)rn ... 10 morern // 在线查了很多资料 依然没有找到原因 在线等 高手 解答 谢谢.rn[/code] 论坛

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