程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> Hibernate: Could not find a getter for iUserId in class com.Hibernate.pojo.User異常,getteriuserid

Hibernate: Could not find a getter for iUserId in class com.Hibernate.pojo.User異常,getteriuserid

編輯:JAVA綜合教程

Hibernate: Could not find a getter for iUserId in class com.Hibernate.pojo.User異常,getteriuserid


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.xml文件中的屬性名和pojo不一致(*.hbm.xml和*.java沒銜接好,不一致),字段屬性沒有正確配置,比如,*.hmb.xml中*.java的地址要明確(明確指出引用包的完整路徑);映射錯誤;有多個主鍵時,對生成的聯合主鍵配置錯誤;拼寫錯誤(包括多空格)等(發生幾率:48%)

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/

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved