今天项目发现一个疑问就是hibernate 映射出来的实体bean对象,里面的属性变了样子。。以至于我在页面上引用,全是抛出EL表达式错误、没有找到相应的映射属性。
就比如标题:N_TITLE 这个是数据库的字段名,我们没有按照规范来写,直接写的N_TITLE,然而获取的时候,缺变成了n_TITLE 不晓得出在哪里的问题
但是比如:AO_TITLE 这样映射出来就没有问题,都是正常的。请问你们遇到这样的问题嘛。
今天还发现一个问题:N_TITLE 只能映射成NTitle ,写成nTitle它也会找不到get,set方法抛出org.hibernate.PropertyNotFoundException: Could not find a getter for nTITLE in class com.legend.shipment.PRISONWB 我晕了!记得hibernate里面的pojo可以随便的写啊?
具体我也想明白是为什么、也许是bug吧:
[color=red]这里有点介绍[url]http://www.iteye.com/topic/88921[/url][/color][color=red]这里有点介绍[url]http://www.iteye.com/topic/6696[/url][/color]
就比如标题:N_TITLE 这个是数据库的字段名,我们没有按照规范来写,直接写的N_TITLE,然而获取的时候,缺变成了n_TITLE 不晓得出在哪里的问题
但是比如:AO_TITLE 这样映射出来就没有问题,都是正常的。请问你们遇到这样的问题嘛。
今天还发现一个问题:N_TITLE 只能映射成NTitle ,写成nTitle它也会找不到get,set方法抛出org.hibernate.PropertyNotFoundException: Could not find a getter for nTITLE in class com.legend.shipment.PRISONWB 我晕了!记得hibernate里面的pojo可以随便的写啊?
具体我也想明白是为什么、也许是bug吧:
package com.bjhy.prisonweb.domain.module.base;
import java.beans.Introspector;
import java.lang.reflect.Method;
public class Test {
private static Method getterMethod(Class theClass, String propertyName) {
Method[] methods = theClass.getDeclaredMethods();
for (int i = 0; i < methods.length; i++)
// only carry on if the method has no parameters
if (methods[i].getParameterTypes().length == 0) {
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];
}
}
// if not "get" then try "is"
/*
* boolean isBoolean =
* methods[i].getReturnType().equals(Boolean.class) ||
* methods[i].getReturnType().equals(boolean.class);
*/
if (methodName.startsWith("is")) {
String testStdMethod = Introspector.decapitalize(methodName
.substring(2));
String testOldMethod = methodName.substring(2);
if (testStdMethod.equals(propertyName)
|| testOldMethod.equals(propertyName)) {
return methods[i];
}
}
}
return null;
}
public static void main(String[] args) {
System.out.println(getterMethod(BaseWebNews.class,"nType"));
}
}
[color=red]这里有点介绍[url]http://www.iteye.com/topic/88921[/url][/color][color=red]这里有点介绍[url]http://www.iteye.com/topic/6696[/url][/color]