5 Replies Latest reply on Aug 6, 2005 8:38 AM by Alan Ho

    EJB3 - EJB-QL

    Bill Burke Master

      It will be a list of Object[].

        • 1. Re: EJB3 - EJB-QL
          Alan Ho Newbie

          Thanks Bill,

          I used the following code to try to retreived two columns but could not get the field correctly after the Object myAccount1 is successfully retrieved from the list. Would appreicate if you can further point out the codes that needs to be implemented. The actBalance field is of data type double and the actActive field is a boolean.

          public List getAccounts(){
          return manager.createQuery("select c.actBalance, c.actActive from Account c").getResultList();
          }

          accountList = accounts.getAccounts();
          for (int i = 0; i < accountList.size(); i++) {
          Object myAccount1 = accountList.get(i);
          }

          • 2. Re: EJB3 - EJB-QL
            Bill Burke Master

             

            for (int i = 0; i < accountList.size(); i++) {
            Object[] myAccount1 = accountList.get(i);
            }
            


            • 3. Re: EJB3 - EJB-QL
              Alan Ho Newbie

              Dear Bill,
              If I coded as you have suggested, it returns as an exception error. The error description seems to indicate that the getresultlist return Object instead of Object[].

              If I changed the statement "Object[] myAccount1 = accountList.get(i);" to "Object myAccount1 = accountList.get(i);" there were no exception errors but displaying the Object shows "[Ljava.lang.Object;@13d285f".

              Is it possible that the statement "return manager.createQuery("select c.actBalance, c.actActive from Account c").getResultList();" is not correctly used???

              for (int i = 0; i < accountList.size(); i++) {
              Object[] myAccount1 = accountList.get(i);
              }


              org.apache.jasper.JasperException: Unable to compile class for JSP

              An error occurred at line: 106 in the jsp file: /accountsetup.jsp
              Generated servlet error:
              Type mismatch: cannot convert from Object to Object[]

              org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
              org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
              org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
              org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
              org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
              org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
              org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
              org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
              org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
              org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
              javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
              org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

              • 4. Re: EJB3 - EJB-QL
                georges goebel Newbie

                Just an idea, but shouldn't it be :

                Object[] myAccount1 = (Object[])accountList.get(i);

                Georges

                • 5. Re: EJB3 - EJB-QL
                  Alan Ho Newbie

                  Thanks Georges,

                  An oversight to cast the Object[] is the cause of the problem.


                  aho