HIBERNATE 实体映射问题

今天项目发现一个疑问就是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吧:
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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值