1
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 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.service(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.

5
  • Since you are explicitly asking for the columns from the table, the result will be an Object[] not Instruction Commented Sep 3, 2016 at 15:17
  • Thanks @Prashanth,tried that but getting java.lang.NumberFormatException: For input string: "instructionKey" this exception Commented Sep 3, 2016 at 15:57
  • Can you post the stack trace? Commented Sep 3, 2016 at 16:15
  • @prasanth, I have updated question, please have a look. Commented Sep 5, 2016 at 13:12
  • I am not sure how to iterate returned Object[] in jsp Commented Sep 5, 2016 at 13:13

1 Answer 1

0

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.