1 Reply Latest reply on Apr 11, 2007 11:05 AM by JOURNADE Valerie

    java.lang.ClassCastException when listing objects

    JOURNADE Valerie Newbie

      Hello all,
      I manage to insert an object with my bean entity but fail when trying to
      list all objects. The following exception occurs:

      javax.ejb.EJBException: java.lang.ClassCastException: org.hibernate.hql.ast.HqlToken
       org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
       org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
       org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
       org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:102)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:211)
       org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
       $Proxy98.listContact(Unknown Source)
       servlet.ListContactServlet.doGet(ListContactServlet.java:23)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
       javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


      my bean entity :
      @Stateless
      @Local(value = { ContactManager.class })
      public class ContactManagerBean implements ContactManager {
       @PersistenceContext(unitName = "contactUnit")
       protected EntityManager em;
      
       public Contact addContact(Contact contact) {
       em.persist(contact);
       return contact; }
      
       public ArrayList<Contact> listContact() {
       return (ArrayList<Contact>)em.createQuery("select contact from contact as contact").getResultList(); }
      }


      Can anyone help me?
      Thanks for helping,

      Cheers.


        • 1. Re: java.lang.ClassCastException when listing objects
          JOURNADE Valerie Newbie

          I try differents request but i have the same exception, so i think it's a pb with my database...
          Here is mi contact-ds.xml on jboss/server/default/deploy :

          <?xml version="1.0" encoding="UTF-8"?>
          <datasources>
          <local-tx-datasource>
          <jndi-name>ContactDS</jndi-name>
          <connection-url><![CDATA[jdbc:mysql://localhost:3306/contact]]></connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>contact</user-name>
          <password>contact</password>
          <exception-sorter-class-name>
           org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
          </exception-sorter-class-name>
          <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
          <metadata>
          <type-mapping>mySQL</type-mapping>
          </metadata>
          </local-tx-datasource>
          </datasources>


          Thanks for your help