4 Replies Latest reply on Nov 23, 2005 1:30 PM by djl1

    ClassCastExeception on EntityBean returned from Stateless Se

    kcturner

      I am attempting to convert an application from EJB2.1 to EJB3.0. I am using JBossAS 4.0.3SP1 EJB3 installation and MyFaces 1.1.1. I am receiving a ClassCastException on an EntityBean that is returned from a method of a stateless SessionBean. I am following the code examples in the tutorial and the DVD example application. The SessionBean method uses the find method of the PersistenceManager to retrieve an EntityBean with its primary key. This works fine, but when the EntityBean is returned to the calling method in a JSP managed bean, a ClassCastException occurs. Any help is greatly appreciated.

        • 1. Re: ClassCastExeception on EntityBean returned from Stateles
          djl1

          If its any consolation, I am having a similar problem (but I think I incorrectly posted it on Javassist forum):

          Seemingly after I pass a Vector, ArrayList or some other concrete collection from a stateless session bean to a client (in a servlet), when I come to do the iteration and thereby casting of the objects, it throws a ClassCastException in the iter.next() statement. Is there something I am doing wrong, as this seems to me to be elementary capability?

          I am running JBoss 4.0.3SP1 on Win 2k (SP4) with Java SDK 1.4.2_04 and Hibernate 3.1RC2 (same as that which comes with JBoss).

          Note that the collection iterates fine at the Session Bean end, so its not Hibernate related.

          • 2. Re: ClassCastExeception on EntityBean returned from Stateles
            bogsolomon

            Try adding a System.out(whateveryouarereturning) or log.debug(whateveryouarereturning) so that you can see the class type of what it is returning. I remember I had the same problem and that helped me. If I remember right I was expecting a Set but it was returning a List.

            In your case if you do a .find that would not be the case but knowing what you get back and what you expect should help.

            • 3. Re: ClassCastExeception on EntityBean returned from Stateles
              djl1

              Thanks, but I think I've sussed it. Fixed it by setting attribute CallByValue in deploy/ear-deployer.xml to true. Not obvious to us newbies, mind.

              Came up in a previous post on Jun 7 (search for ClassCastException).

              • 4. Re: ClassCastExeception on EntityBean returned from Stateles
                djl1

                Incidentally, I did try your suggestion "Bog", and it returned the correct class name that I was expecting; just when it came to casting, it threw a CCE wobbly.

                Another thing I tried was to rearrange the war file to remove any duplicate pojo jar files (from another posted solution to a CCE problem), but that made no difference. However, now I understand a bit more about the class loader, so I can slim my war files down!