For your session bean to look up your entity bean, it should use
"java:comp/env/" plus the <ejb-ref-name>. In this case, this means
you should use "java:comp/env/MyEntity". The "ejb/" is a convention
that is not universally followed, but if you set your reference to
<ejb-ref-name>ejb/MyEntity</ejb-ref-name>, then by the logic above,
you'd look it up at "java:comp/env/ejb/MyEntity". If you don't put
the ejb/ in your ejb-ref-name, then you can't use it in your JNDI
lookup.
FYI, your openejb-jar.xml content is not necessary for lookups to work
between EJBs (only for an application client that wants to look up an
EJB).
Thanks,
Aaron
On 5/16/06, mahu2425 <[EMAIL PROTECTED]> wrote:
Hi there,
I'm trying to access an entity bean from a stateless session bean and I'm running into a
"javax.naming.NameNotFoundException" while executing the followin statement:
ctx.lookup("java:/comp/env/ejb/MyBean");
ctx is an InitialContext without parameters. Both EJBs are running on the same
server and and are in the same archive.
My ejb-jar.xml contains the following code (I will leave out tags like
cmp-fields in this posting, btw: the session bean serves additionally as a web
service):
<session>
<display-name>Demo</display-name>
<ejb-name>Demo</ejb-name>
<home>com.test.DemoHome</home>
<remote>com.test.Demo</remote>
<service-endpoint>com.test.DemoSEI</service-endpoint>
<ejb-class>com.test.DemoBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<ejb-ref>
<ejb-ref-name>MyEntity</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.all.MyEntityHome</home>
<remote>com.all.MyEntity</remote>
<ejb-link>MyEntity</ejb-link>
</ejb-ref>
</session>
<entity>
<description>Test entity bean</description>
<ejb-name>MyEntity</ejb-name>
<home>com.all.MyEntityHome</home>
<remote>com.all.MyEntity</remote>
<ejb-class>com.all.MyEntityBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>false</reentrant>
<cmp-version>2.x</cmp-version>
<abstract-schema-name>MyEntity</abstract-schema-name>
</entity>
My openejb-jar.xml contains the following code (I'll leave out things like
cmp-mappings in this posting)
<enterprise-beans>
<session>
<ejb-name>Demo</ejb-name>
<jndi-name>Demo</jndi-name>
</session>
<entity>
<ejb-name>MyEntity</ejb-name>
<jndi-name>MyEntity</jndi-name>
</entity>
</enterprise-beans>
As I said before, a lookup is not possible.
During several tries I changed the <jndi-name> for the entity bean in openejb-jar.xml to
<jndi-name>ejb/MyEntity</jndi-name>
and the <ejb-ref-name> in ejb-jar-xml to
<ejb-ref-name>ejb/MyEntity</ejb-ref-name>
And magic: the lookup works. Unfortuanally I can not understand why. Is a leading
"ejb/" required for jndi name? I don't think so, because I could not find
anything similar in any tutorial. But what is the difference or what are the underlying
rules?
Greets,
Markus
Schnell und einfach ohne Anschlusswechsel zur Lycos DSL Flatrate wechseln und 3
Monate kostenlos ab effektiven 5,21 EUR pro Monat im ersten Jahr surfen.
http://www.lycos.de/startseite/online/dsl/index.html?prod=DSL&trackingID=email_footertxt