PEARCE TOMENIUS Zina <[EMAIL PROTECTED]> schrieb am 29.08.2002,
12:15:33:
> Hi,
>
> I have a Stateful session Bean which accesses a CMP 2.0 Bean via its local
> interface in Weblogic 6.1 (SP 2). I get a class cast exception after the
> following code in the session bean, when i try to get hold of the Local Home
> interface of the CMP bean.
>
> InitialContext initCtx = new InitialContext();
> //cast to Home interface
> CheckListEntityHome localHome =
> (CheckListEntityHome)initCtx.lookup("CheckListEntity");
>
> The error message is as follows:
>
> java.lang.ClassCastException:
> com.intrasoft.wfs.control.ejb.checklist.CheckListEntityBean_2qk0fd_LocalHome
> Impl at
> com.intrasoft.wfs.control.ejb.checklist.CheckListManagerBean.getCheckList(Ch
> eckListManagerBean.java:79)
>
> The class 'CheckListEntityBean_2qk0fd_LocalHomeImpl ' correcly implements
> the CheckListEntityHome interface.
>
> Does anyone know why this is happening? I thought that using the default
> constructor for InitialContext and not using RMI narrowing, was ok for local
> interfaces.
>
> Thanks.
Hi Zina,
this looks like a missing <ejb-ref> in your deployment descriptor. If
you want to access a bean B from a bean A, there must be an EJB
reference to B inside A's deployment descriptor. This will create an
entry in A's environment that you can lookup like this:
InitialContext initCtx = new InitialContext();
BLocalHome localHome =
(BLocalHome)
initCtx.lookup(
"java:comp/env/ejb/BRef"
);
The idea behind this is that bean developers for bean A should *not*
need to know the absolute JNDI name of bean B because the deployer might
decide to put bean B onto another server (after the fact).
BTW, I never understood why application servers throw a
ClassCastException if I omit the ejb-ref. Does anyone on the list know
this?
Cheers...
Matthias Bohlen
http://www.mbohlen.de/
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".