hibernate 特殊情况下 属性找不到get方法的解决方案
来源:互联网 发布:属于淘宝禁售商品刀 编辑:程序博客网 时间:2024/04/27 22:58
Caused by: org.hibernate.PropertyNotFoundException: Could not find a getterfor pOrgID in class com.oarage.basedata.commons.entity.UnloadOil
我说的情况是属性名称第一个字母小写,第二个字母大写,例如:eTypeName,则按照javabean specification规定的getter方法为getETypeName,则会出现找不到getter方法的错误。
今天看了一下javabean specification,规定了一般的属性名称首字母小写,如果遇到前两个字母大写的属性,则getter方法保持属性名称不变,例如URL属性的getter方法为getterURL,但是并没有规定类似eTypeName这样的属性的getter方法写成geteTypeName的形式。
如果Hibernate实体属性名称 第2个字母是大写 或者 出现两个字母大写:
hibernate 3.2.5.ga中会出现错误:Could not find a getter for “fieldName”
hibernate3.2.7中会出现错误: Unable to instantiate default tuplizer
Hibernate用的方法是 :BasicPropertyAccessor.java
String methodName = methods[i].getName();
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);
Sun的注释说明
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之后不修改首位字符,就Could not find a getter for xSize了
这个是Java Bean的Spec里面规定的。方法有多种,你可以写成xsize这种全部小写,或者加"_"字符,如果你首位大写不在第二位就没问题了。
另外出现Unable to instantiate default tuplizer错误可能的原因:
是某个实体类中外加了某些getXX(),而不存在XX属性,这时要在get上加@Transient,不持久 化它就行了
参考:
http://blog.163.com/ace_ning/blog/static/1208726912009612815294/ ,hibernate实体类属性第二个字母大写Could not find a getter for问题
http://blog.csdn.net/jjss2006/archive/2009/08/21/4470702.aspx,异常:Unable to instantiate default tuplizer
- hibernate 特殊情况下 属性找不到get方法的解决方案
- get与post的一些特殊情况
- final()方法的特殊情况
- Hibernate Transformers.aliasToBean找不到属性方法
- hibernate的get方法
- TextView跑步灯效果及在特殊情况下无效的解决方案
- EasyUI特殊情况下的BUG整理
- java方法的重载与特殊情况
- maven 类,方法找不到的情况
- ajax特殊情况下被动返回了新页面的处理方法
- eclipse和myeclipse下main方法找不到主类的一种情况
- myeclipse + Maven下main方法找不到主类的一种情况
- javascript对象属性命名“”增添的特殊情况
- hibernate在设置懒加载的情况下如何立即加载某些属性
- centOS7 下找不到eth0 的解决方案!
- Ubuntu下 dos2unix:找不到命令 的解决方案
- hibernate的注解为何要在属性的get方法上声明
- hibernate的注解为何要在属性的get方法上声明
- php中自定义自动加载函数
- 计算机科学中最重要的32个算法
- 招致创业失败的七个错误
- JSON学习笔记(格式/第三方库jsonCpp与libJson的配置和使用) cocos2d-x
- [Leetcode]Best Time to Buy and Sell Stock III
- hibernate 特殊情况下 属性找不到get方法的解决方案
- CF 196B(Psychos in a Line-单调队列贪心)
- 这次真的谈谈如何管理一流人才
- error RC1004: unexpected end of file found处理方法
- 11年写的一篇文章----智能终端安全现状及前景展望
- spring + struts2 + hibernate 集成
- Android资源文件及文件夹介绍
- 原来程序员也有桃花运【爱情奇遇】
- java 自定义注解使用