public List<Instruction> listPAyment() {
Session session = this.sessionFactory.getCurrentSession();
List<Instruction> personsList = (List<Instruction>)session.createSQLQuery(
"SELECT INSTRUCTIONKEY, BASECURRENCY,STATUSPROC, WHENMODIFIED FROM MyDB.INSTRUCTION"
).list();
EXCEPTION HERE---> for(Instruction p : personsList){
System.out.println( "Payment::"+ p.toString());
}
return personsList;
}
我在上述问题上得到java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction
例外,我无法找出在下面的代码中投射有什么问题。
我已在模型类toString()
Instruction
请协助
[2016/09/05 15:05:01:991 GMT + 02:00] 00000040 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper服务SRVE0068E:其中一种服务方法抛出异常应用程序[SpringMVCHibernate_war]中的servlet [/WEB-INF/views/instruction.jsp]。创建异常:[java.lang.NumberFormatException:对于输入字符串:“instructionKey” at java.lang.NumberFormatException.forInputString(NumberFormatException.java:59) 在java.lang.Integer.parseInt(Integer.java:460) 在java.lang.Integer.parseInt(Integer.java:510) 在javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166) 在javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46) 在javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55) 在org.apache.el.parser.AstValue.getValue(AstValue.java:174) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:283) at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:778) at com.ibm._jsp._instruction._jspx_meth_c_forEach_0(_instruction.java:131) 在com.ibm._jsp._instruction._jspx_meth_c_if_0(_instruction.java:179) 在com.ibm._jsp._instruction._jspService(_instruction.java:95) 在com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:668) 在com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307)
Jsp迭代对象:
<c:forEach items="${listPersons}" var="instruction">
<tr>
<td>${instruction.instructionKey}</td>
<td>${instruction.statusProc}</td>
<td>${instruction.baseCurrency}</td>
<td>${instruction.whenModified}</td>
</tr>
</c:forEach>
其中model.addAttribute(“instruction”,new Instruction()); model.addAttribute(“listPersons”,this.personService.listPersons());
在控制器中定义。