3 Replies Latest reply on Apr 26, 2006 11:46 PM by javidjamae

    JNDI lookup returns $Proxy object

    peafunk

      Hi,

      I am having an issue configuring a datasource with JBoss. When I perform a lookup of the datasource from outside of the web application, it returns a $Proxy# object instead of a javax.sql.DataSource object. I've scoured the forums here and tried to resolve this myself but haven't been able to. The most popular cause of the problem seems to be that a different classloader is being used to retrieve the object from JNDI but I'm not sure how that is happening or how to fix it. I am using the exact same classpath and have included in the classpath the jbossall-client.jar from the jboss/client directory. I also setup the datasource in the Global JNDI Namespace, not the java: namespace. Has anyone else experienced this or know what I might be doing wrong? I can post all the code if need be. Thanks in advance for any help.

        • 1. Re: JNDI lookup returns $Proxy object
          javidjamae

          Stupid question, but have you tried casting it to a DataSource? If you are getting a ClassCastException when you try to do a JNDI lookup, it is usually a classpath issue. Try including all of the JARs from the client directory in your classpath and remove any J2EE jars that weren't distributed with the version of JBoss that you're using.

          • 2. Re: JNDI lookup returns $Proxy object
            peafunk

            Thanks for getting back to me. I finally figured this out, it was what you mentioned. I had to remove all other J2EE jar files and include jboss-j2ee.jar in the classpath. The problem was I had two different versions of javax.sql.DataSource in the classpath.

            Thanks for the help!

            • 3. Re: JNDI lookup returns $Proxy object
              javidjamae

              Another cause that I've seen is when you try to cast the return value of the JNDI lookup on an EJB to the bean type rather than the interface type.

              //This works
              GreeterRemote myGreeter = (GreeterRemote) ctx.lookup("GreeterBean/remote");
              
              // This doesn't work (throws "ClassCastException: $Proxy0")
              GreeterBean myGreeter = (GreeterBean) ctx.lookup("GreeterBean/remote");


              Of course, you shouldn't be doing the second one, because the client should only be dealing with the remote interface.