File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes class casting with ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "class casting with ejb" Watch "class casting with ejb" New topic
Author

class casting with ejb

Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Hi,

I have an EJB client:



HelloWorld is an implementation class of HelloWorldRemote.

I have class cast exception that wrapper cannot be cast on HelloWorld.

When I use:
HelloWorldRemote hw = (HelloWorldRemote) ctx.lookup("ejb/HelloWorldBean");
everything runs flawlessly.

Can someone describe me this situation?


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2246

Howdy, Lucas.

Well champ, can you show us the code of HelloWorldBean, HelloWorld and HelloWorldRemote? Can you show us the exception's stack trace?


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Unless the client is a local client to the EJB and uses a no-interface view of the EJB, you cannot use the implementation class when casting the result of the lookup.
In your case, what I can tell is:
1. The client is not a local client of the EJB, since it seems to be executing in another JVM than the EJB.
2. The EJB implements a remote interface. If you haven't explicitly annotated the EJB implementation class with @LocalBean, then there is no local view of the EJB.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class casting with ejb
 
Similar Threads
can call EJB from Java App But not from Servlet
PortableRemoteObject exception
Using stand alone client appication
Simple EJB3 session beans not deploying in JBOSS6
Hello world example using EJB 3