你的位置:首页 > Java教程

[Java教程]Hibernate: Could not find a getter for iUserId in class com.Hibernate.pojo.User异常


org.hibernate.PropertyNotFoundException: Could not find a getter for iUserId in class com.Hibernate.pojo.User

 at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282) at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275) at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168) at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294) at com.Hibernate.service.BusinessServiceH.<clinit>(BusinessServiceH.java:25) at com.Hibernate.test.BusinessServiceHtest.test(BusinessServiceHtest.java:28) at com.Hibernate.test.BusinessServiceHtest.main(BusinessServiceHtest.java:46)Exception in thread "main" java.lang.NullPointerException at com.Hibernate.service.BusinessServiceH.saveUser(BusinessServiceH.java:36) at com.Hibernate.test.BusinessServiceHtest.test(BusinessServiceHtest.java:40) at com.Hibernate.test.BusinessServiceHtest.main(BusinessServiceHtest.java:46)

 



可能原因如下:

1.真的没有写getter方法(发生几率:1%)

2.*.hmb.

3.方法写错/方法名写错,要按照javabean的书写规范写啊,要不然打死也找不到哪儿错了(发生几率:50%)

这里提一下:get/set是不是不允许方法名中有连续两个大写字母,例如

public String getODPType(){    return this.oDPType;}public void setODPType(String   oDPType){this.oDPType = oDPType;}

 

这样写它就会报错,报找不到getter for oDPType的错误,但下面这样写就可以了

public String odpType;public String getOdpType(){    return this.odpType;}public void setOdpType(String   odpType){this.odpType = odpType;}

 

4.其他不明原因(发生几率:1%)

 

来自: http://qiji214.blog.163.com/blog/static/1200522920099140712529/