Hi
I have become very confused about how to go about
referencing
one EJB from another - I am hoping that someone out
there will
be able to set me straight. Please help cos I am
tearing my hair
out over this!

I will set out what I think goes on - please let me
know if I have
got hold of the wrong end of the stick anywhere.

Ok so we want to get hold of the home interface of
another bean -
it seems to me the first way to do this is with a
'standard' JNDI
lookup, viz

Context ctx = new InitialContext();
Object ref = ctx.lookup("TargetBeanHome");
targetHome =
(TargetHome)PortableRemoteObject.narrow(ref,TargetHome.class);

Here we use the no-arguments constructor to get a
context with the naming service
( which naming service is presumably specified in the
jndi.properties file
  - although I think IAS does some sort of automatic
discovery???)
and then lookup the JNDI name of our home interface.

The thing about this is that we have hardcoded the
JNDI name. I assume that
this is what ejb-references are for - avoiding
hardcoding the JNDI name, like so

Context ctx = new InitialContext();
Object ref =
ctx.lookup("java:comp/env/ejb/TargetBean")
targetHome =
(TargetHome)PortableRemoteObject.narrow(ref,TargetHome.class);

and then in the DD

<ejb-ref>
        <ejb-ref-name>ejb/TargetBean</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <home>TargetHome</home>
        <remote>Target</remote>
</ejb-ref>

now we are looking up a reference in the EJB
environment naming context
rather than the JNDI name directly. Of course we still
need to bind this
reference to the correct Home interface. The spec
specifies that this is the
resposibility of the deployer but seems to leave how
it should be specified open
to be implementation dependent. ( IAS seems to require
an Inprise-specific DD
that links the ref-name with the JNDI name of the
target bean )

on the other hand it seems you can also use an
ejb-link tag in the DD to link the reference to a
Home interface by specifying the ejb-name of the
target bean. Then I assume you do
not need to to worry about specifying the target JNDI
name since you are directly linking
to the ejb-name, and I would also assume that since we
are now linking to the
ejb-name the target EJB must be specified in the same
DD and hence the same jar as your client bean.
( and indeed IAS would not let me deploy a bean who's
DD had a ejb-link to a bean
  in a different jar )

However the spec states that ejb-links can be used
between beans in different jars
  if they are in the same J2EE application unit - what
does that mean?? I cant find
the a definition of 'J2EE application unit anywhere'.

I assume that the point of using ejb-links is that
they allow the container to somehow
'shortcut' the naming lookup process for beans that
are deployed together without having
to access the naming service...???

By contrast if you use a ejb-ref without a link and
bind it to a target beans JNDI name I assume
that the target bean can be anywhere, even deployed in
another container so long as
the naming service knows about it.

Is any of this even close?

__________________________________________________
Do You Yahoo!?
Yahoo! Photos - Share your holiday photos online!
http://photos.yahoo.com/

===========================================================================
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".

Reply via email to