3 Replies Latest reply on Oct 27, 2002 6:47 PM by sgturner

    Overriding toString in EJB

    icanoop

      Hi,

      I ran into a problem where I wanted to override the toString method in my CMP entity bean, and make it available in my remote interface.

      It compiled fine and deployed and all, but when my client called it, the default toString from Object was called instead. I was unable to call my implementation of toString.

      I fixed the problem by changing the name from toString to viewString, but I would like to understand the problem.

      Does anyone know why toString wouldn't work for me? Is it possible to implement your own toString method for an entity bean?

      Just curious,
      Ryan

        • 1. Re: Overriding toString in EJB
          sgturner

          Did you add toString() to the interface? I'm not sure, but this may have something to do with the way JBoss optimzes method calls. Method calls like to String() are handled in the JVM which originated the call and not sent to the server side. Perhaps one way to handle this bug/feature ? is to replace the client side interceptor that does this with one of your own. But I don't know for sure, just some thoughts that come to mind.

          • 2. Re: Overriding toString in EJB
            icanoop

            > Did you add toString() to the interface?

            Yes, it was in the interface.

            > Method calls like to String() are handled in the JVM
            > which originated the call and not sent to the server
            > side.

            Cool, so when you say method calls like toString(), which other methods are included? Is there a rule that says some methods will not be sent to server, but rather handled by the client?

            > Perhaps one way to handle this bug/feature ? is to
            > replace the client side interceptor that does this with > one of your own.

            Well, since I am no java or j2ee expert, and I don't even know what that means, I guess changing the method name is better for me right now. Although I have always liked the java practice of calling the method that converts to a string toString().

            • 3. Re: Overriding toString in EJB
              sgturner

              Its been a while since I looked at the code, but the methods that are handled on the client side are hard coded, as I remember. I don't remember what other methods. Gee, you could write an interceptor that gave you the ability to turn off this feature on a per method name basis.