今天做Hibernate的时候如果我的pojo里面的属性是这样的:private Integer bId,结果就会报告
Could not find a getter for bId in class wj.pojo.Building当我改成buildingId的时候就完全没有问题了,改成bid也完全没问题,就是第一个小写,第二个字母大写的时候有问题,我操他妈居然还能这样!真是太令人费解了!
private Integer buildingId;
private Integer bid;
上面这么写就没问题
哪位大哥遇到过这样的问题啊?

解决方案 »

  1.   

    当你 第二个字母是 大写的时候 getter 就变为  getBId 了~,我以前貌似遇到过,就改变量名字了  没办法 哎
      

  2.   

    是有这个问题,一般属性命名时前保证两个字母小写就不会出现问题
    它生成的回事getBId()/setBId()方法,由于get/set后面出现里两个大写字母会找不到,具体我也解释不清楚了
      

  3.   

    你的get set方法改过来没有?
    还有其它的配置...
      

  4.   

    1.希望楼主不要说脏话2.你改了数据域某个变量的名字,但是getter和setter方法的名字也要随着改变的,看看是不是忘记了或改错了?
    对于bId,   应该有public Integer getBId()和public void setBId(...)
      

  5.   

    这个只能够说明一点问题
    那就是你的set方法出了问题
      

  6.   

    谢谢大家的意见,我找到了问题所在,自问自答了!!!
    如果我们在HBM.XML中定义 java代码:  <property name="xRatio" type="float"/> 问题就出在xRatio由两部分x和Ratio组成,而其中的第一部分只有一个字母。具体原因见后边的分析。 在创建Session的时候会告诉你Could not find a getter for xSize 经过Debug看了一下发现不是Hibernate的问题 Hibernate用的方法是 java代码:   BasicPropertyAccessor.java String methodName = methods[i].getName(); // try "get" if( methodName.startsWith("get") ) {         String testStdMethod = Introspector.decapitalize(methodName.substring(3) );         String testOldMethod = methodName.substring(3);         if( testStdMethod.equals(propertyName) || testOldMethod.equals(propertyName) ) return methods[i];        }    他调用的是 Introspector.decapitalize(String name); JDK API中对Introspector.decapitalize的注释说明 but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone. 他得到getXSize这个方法名,substring[3]为XSize然后decapitalize之后不修改首位字符,就是XSize。那么,上述代码中的testStdMethod和testOldMethod就都是XSize,与propertyName的xSize均不相同,于是就Could not find a getter for xSize了 。 这个(第一个单词首字母小写,其余每个单词首字母大写)是Java Bean的Spec里面规定的。解决方法有多种,关键在于破坏两个连着的大写字母。你可以写成xsize这种全部小写,或者加"_"字符,如果你首位大写不在第二位就没问题了。  Hibernate的FAQ里面也有记录,简单提到了这个问题  I have a property named like getAFoo() / setAFoo() and Hibernate throws a PropertyNotFoundException at startup. Use name="AFoo" from the property name, as per the JavaBeans spec.
      

  7.   

    呵呵 我测试了一下用 private Integer bId;  的话 你的xxx.hbm.xml 里的
     <property name="BId" column="BId" /> 换这个就可以了~ 读取XML的原因吧
      

  8.   

    CMB_LAFENG这位兄弟,你真是有点歪的邪的
    Introspector的decapitalize方法:把一个String的首字母从大写变成小写,
    Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL". 
    but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone.
    但是当开始是两个都是大写的话就忽略不管了