简体   繁体   中英

java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction

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;
}

I am getting java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.spring.model.Instruction exception at above mentioned point, I am unable to find out what's wrong with casting in below code. I have added toString() correctly in model class Instruction

Please assist

[2016/09/05 15:05:01:991 GMT+02:00] 00000040 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [/WEB-INF/views/instruction.jsp] in application [SpringMVCHibernate_war]. Exception created : [java.lang.NumberFormatException: For input string: "instructionKey" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:59) at java.lang.Integer.parseInt(Integer.java:460) at java.lang.Integer.parseInt(Integer.java:510) at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:166) at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:46) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:55) at 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) at com.ibm._jsp._instruction._jspx_meth_c_if_0(_instruction.java:179) at com.ibm._jsp._instruction._jspService(_instruction.java:95) at com.ibm.ws.jsp.runtime.HttpJspBase.service(HttpJspBase.java:99) at javax.servlet.http.HttpServlet.serv ice(HttpServlet.java:668) at com.ibm.ws.cache.servlet.ServletWrapper.serviceProxied(ServletWrapper.java:307)

Jsp to iterate object:

      <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>

where model.addAttribute("instruction", new Instruction()); model.addAttribute("listPersons", this.personService.listPersons());

defined in controller.

You could pull from the DB into a class named :whatever: and give that class the variables that will be pulled from the DB and give it a toString method that you can call? Maybe?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM