Hibernate统计时的
java.lang.ClassCastException: java.lang.Long错误请解
程序为一段统计表中记录数:
===================================================================
this,countHql= "select count(rc.id) from RCdata rc "
List l = this.
getHibernateTemplate().find(this.countHql);
if (l != null && !(l.isEmpty())) {
this.totalRows = ((Integer) l.get(0)).intValue();//Exeception就发生在这
}
else {
return false;
}
这段程序运行find都没错,通过单步可以看到List l都得到正确的值了,可是在将List转为Integer存到this.totalRows时发生了cast错误,不知道什么原因?
===================================================================
错误信息:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.Long
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535) org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
java.lang.ClassCastException: java.lang.Long
com.dmaple.ezlife.dao.hibernate.CommonPageHibernateDAO.canDoNow(CommonPageHibernateDAO.java:91)
com.dmaple.ezlife.service.imp.AdminServiceImp.getCorpRecords(AdminServiceImp.java:116)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:280)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
$Proxy1.getCorpRecords(Unknown Source)
com.dmaple.ezlife.web.action.AdminCorpMaintainAction.execute(AdminCorpMaintainAction.java:43)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)