This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Error while using lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Error while using lookup" Watch "Error while using lookup" New topic
Author

Error while using lookup

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Hi! I have a code for an Enterprise application. It contains files for a web application and an ejb mixed. I had to run it. So what I did was that I separated the files of the ejb, web and the enterprise application. Then I created projects using netBeans for all of these three. Then I build the EJB project so it generated a .jar file for the project. Then the web application was using the EJBs so I gave the path of the .jar file of the ejb project i.e. the final distributable file of the ejb project. Then I added these modules into the enterprise application and deployed it.

I gave the above information as there might be a problem in the above process. Now ehen one of the web pages uses InitialContext.lookup, a correct object is being returned i.e. the actual bean object. But when I convert the object to it's interface type, I get a ClassCastException: $Proxy430. This number after Proxy changes whenever I rebuild my project. So basically I think this is related to version of the files. So by the above information, can you figure what I am doing wrong.

I would be really thankful to anyone who could help (I am still thankful to Jaikiran who helped me here)


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

I guess you are using JBoss

Can you post the entire exception stacktrace and also the output of the JNDI tree? And please also post your code where you are doing the lookup and the cast.


[My Blog] [JavaRanch Journal]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

OK! This is the stack trace



This is the JNDI tree output related to the thing I am looking for

+- ejb (class: org.jnp.interfaces.NamingContext)
| +- AuthenticatorLocal (proxy: $Proxy387 implements interface uk.co.alterhit.cms.ejb.interfaces.AuthenticatorLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)
| +- CmsUserManagerLocal (proxy: $Proxy385 implements interface uk.co.alterhit.cms.ejb.interfaces.CmsUserManagerLocal,interface org.jboss.ejb3.JBossProxy,interface javax.ejb.EJBLocalObject)

I have not used code tags with this as it will disturb the layout. This is the lookup code

AuthenticatorLocal authenticator = (AuthenticatorLocal) ctx.lookup("ejb/AuthenticatorLocal");

The lookup is returning an object of type AuthenticatorBean which implements AuthenticatorLocal...
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

This looks like a classloading issue. Are you packaging the EJB interfaces in both the WAR as well as the EJB jar in the EAR? If yes, then remove the EJB interfaces from the WAR. See this for details.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Hi Jaikiran. I don't have the classes and interfaces in my web application. I checked the page that you gave and tried what was told on the page. I am only getting 1 instance of the ejb so that doesn't seem to be the problem. Here is the output of the jmx console when I did what was given on the page that you provided

++++CodeSource: (file:/F:/jboss-4.0.4.GA/server/default/tmp/deploy/tmp54283AlterhitCms.ear-contents/cms-ejb.jar )
Implemented Interfaces:

### Instance0 found in UCL: org.jboss.mx.loading.UnifiedClassLoader3@550344{ url=file:/F:/jboss-4.0.4.GA/server/default/tmp/deploy/tmp54283AlterhitCms.ear ,addedOrder=49}


So as you can see, there is only one instance of the ejb...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

I got it solved

It was a matter with another ejb which I was also using. Actually in Netbeans there is an option to add a project (lets say project1) as a library to another project (lets say project2) for compiling the files in the second project (i.e. project2). When I did that my netbeans got hang. So instead of the project, I added the .jar file of the project (i.e. project1) into the second project (i.e. project2). This was creating the problem.

THANK YOU SO MUCH JAIKIRAN. You are my HERO (You would have been more happy if my name was Ankita )
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

Do you include any JBoss specific jar files in your application package? Post the output of:

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Jaikiran no need for that. I got it working. Looks like you were typing the response when I posted that it is working
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9930
    
159

Originally posted by Ankit Garg:
Looks like you were typing the response when I posted that it is working


Yes Good to know it worked!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Error while using lookup
 
Similar Threads
java.sql.SQLException: No suitable driver
157 Question Help and Resourses
IBM Exam 157 - Questions and Answers (Sample Exam)
ibm websphere test 157 for websphere studio application developer 4.0.3 for windows
jboss not able to read .war file