You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Alexander Taylor <al...@logisticchaos.com> on 2005/05/25 15:20:30 UTC

EJB3/JBoss Entity Bean remoting issue

Hi, 
I am having an issue with a ClassCastException whilst trying to remote
an EJB3 entity bean. 

I have a simple Entity bean "Account" which appears to function
perfectly. I then have a stateless session bean with the following
function: 

public Account findAccountById(int id) { 
Account a = (Account)manager.find(Account.class, id); 
} 

I.e. return the account that matches the given id. 

In my client (on top of Tomcat 5.5 - external to JBoss - I know perhaps
that this is not currently supported, but it seems to work in most
cases), I have a call in a Spring MultiActionController: 


AccountServices service = (AccountServices)
context.lookup(AccountServices.class.getName()); 
Account a = service.findAccountById(id); 

Which causes: 

java.lang.ClassCastException: db.mapping.Account 
at $Proxy0.findAccountById(Unknown Source) 
at
web.AccountMAController.showAccountSummary(AccountMAController.java:43) 

etc.. 

Interestingly, if I return the account in an ArrayList from the function
findAccountById (i.e. getResultList), and pass this resultant list to a
JSP page, and inject the arraylist as a bean - I can access the members
of the Account object perfectly. 

Also, if I return the Entity bean as an "Object", and pass this object
through to a jsp, this works too - i.e. i can access the members.  So my
object is clearly of the type db.mapping.Account, but casting to it
causes the above exception.

This exception is the only output given (other than the full stack
trace) - nothing goes to catalina.out

I cannot fault my code, and indeed this workaround seems to work - so my
EJB is clearly returning the correct data, but I cannot cast to the
Account object from within the servlet. 

I am running this on Tomcat 5.5.9.

There is no exception thrown on the JBoss Server, so there would appear
to be some issue with the Tomcat class-loader here.

Ideas anyone?

Cheers,
Alex.


-- 
Alexander Taylor <al...@logisticchaos.com>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: EJB3/JBoss Entity Bean remoting issue

Posted by Julian Templeman <ju...@gmail.com>.
> AccountServices service = (AccountServices)
> context.lookup(AccountServices.class.getName());
> Account a = service.findAccountById(id);

One thing occurs immediately: The lookup will be fine if
AccountServices is a local interface on the bean. If it is a remote
interface, you'll need to narrow the reference before you can cast it.

julian

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org