ejb@glassfish.java.net

Re: EJB Class Cast Exception

From: Kenneth Saks <Kenneth.Saks_at_Sun.COM>
Date: Tue, 26 Sep 2006 17:05:01 -0400

Lichtenwalter, Ryan wrote:

> Greetings,
>
> I am working with EJBs in the Sun Java System Application Server 9.
> When I follow these instructions:
>
> InitialContext ic = new InitialContext();
> Foo foo = (Foo) ic.lookup("FooEJB");
>
> On my code, which is as follows:
>
> Context theContext = new InitialContext();
> QueryLibraryBean theBean =
> (QueryLibraryBean)theContext.lookup("jdbc/QueryLibraryEJB");
> theBean.getData();
>
Hi Ryan,

It looks like the code is casting to the bean class instead of the
business interface.
In EJB, the cilent does not have any visibility to the bean
implementation class.
Assuming the business interface is QueryLibrary, it would be :

  QueryLibrary queryLibrary = (QueryLibrary)
theContext.lookup("jdbc/QueryLibraryEJB");
 

>
> I get the following exception:
>
>
> java.lang.ClassCastException: QueryLibrary._QueryLibraryRemote_Wrapper
> at test.Main.main(Main.java:14)
>
> Upon further examination, I found that the lookup call, which is in
> fact contacting the application server and finding my QueryLibrary
> bean, is not returning the QueryLibraryBean object, but is instead
> returning a wrapper class, _QueryLibraryRemote_Wrapper
>
> I do not know how my code differs from the example you provide on your
> "glassfish: EJB FAQS" page, but I am at a loss as to how I can correct
> this.
>
> Ryan Lichtenwalter
> Lockheed Martin Corporation
> Software Development
> 651-456-7590
>