我的代码是
private List find(String queryString) {
final Query query = getSession().createQuery(queryString.intern());
List resultSet = query.list();
return resultSet;
}
@SuppressWarnings("rawtypes")
public List < CrExcessMaster > getExcessesWidget(String primaryCO) {
List cifList = find("select cem.id.cifNumber from CrEntitymaster cem where cem.primaryCo='" + primaryCO + "'");
List < CrExcessMaster > temp = null;
for (int i = 0; i < cifList.size(); i++) {
log.info("cifList in dao " + cifList);
if (i == 0) {
temp = find("from CrExcessMaster where cif='" + cifList.get(i) + "'");
} else temp.add((CrExcessMaster) find("from CrExcessMaster where cif='" + cifList.get(i) + "'"));
}
return temp;
}
其中 crExcessMaster 是一个表,我需要显示变量临时值...但是当我尝试调用上面的返回值时,如下所示
public static FilteredUIExcessList formatCustomerExcessUiBean(List < CrExcessMaster > crExcessMasterList) {
if (crExcessMasterList != null) {
FilteredUIExcessList filteredUIExcessList = new FilteredUIExcessList();
< font color = red >
for (CrExcessMaster crExcessMaster: crExcessMasterList) < /font>{
ExcessUIBean excessUIBean = new ExcessUIBean();
excessUIBean.setCurrency(crExcessMaster.getCurrency());
}
在以红色突出显示的代码处,它正在抛出 classcast 异常
java.lang.ClassCastException: java.util.ArrayList cannot be cast to cib.ecm.creditRisk.excessManagement.db.orm.CrExcessMaster
全栈跟踪是
java.lang.ClassCastException:java.util.ArrayList 无法在 cib.ecm.creditRisk.excessManagement.web.uiFormatters.UIBeanFormatter.formatCustomerExcessUiBean(UIBeanFormatter.java:65) 处转换为 cib.ecm.creditRisk.excessManagement.db.orm.CrExcessMaster ) 在 cib.ecm.creditRisk.excessManagement.web.action.ExcessListActionBean.getExcessesWidget(ExcessListActionBean.java:105) 的 cib.ecm.creditRisk.excessManagement.web.services.ExcessManagementUiService.getExcessesWidget(ExcessManagementUiService.java:52)。 reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net。 sourceforge.stripes.controller.DispatcherHelper 6 美元。在 net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113) 在 net.sourceforge .stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155) 在 net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74) 在 net.sourceforge.stripes.controller.DispatcherHelper.invokeEventHandler(DispatcherHelper.java :440) 在 net.sourceforge.stripes.controller.DispatcherServlet.doPost(DispatcherServlet.java:167) 在 net.sourceforge.stripes.controller 的 net.sourceforge.stripes.controller.DispatcherServlet.invokeEventHandler(DispatcherServlet.java:285)。 javax.servlet 中的 DispatcherServlet.doGet(DispatcherServlet.java:67)。http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org .mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221) at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:246) at org.mortbay.jetty.servlet.ServletHandler$CachedChain .doFilter(ServletHandler.java:1212) 在 cib.ecm.creditRisk.excessManagement.web.filter.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:35) 在 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java :1212) 在 org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399) 在 org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 在 org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 在 org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) 在 org.mortbay.jetty.webapp.WebAppContext .handle(WebAppContext.java:450) 在 org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) 在 org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) 在 org. mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 在 org.mortbay.jetty.Server.handle(Server.java:326) 在 org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)在 org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928) 在 org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549) 在 org.mortbay.jetty.HttpParser。在 org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) 在 org.mortbay.handle(HttpConnection.java:404) 在 org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 的 parseAvailable(HttpParser.java:212) 在 org.mortbay.thread .QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)