users@glassfish.java.net

Re: JNDI question

From: Cheng Fang <Cheng.Fang_at_Sun.COM>
Date: Wed, 24 Oct 2007 10:23:28 -0400

In glassfish you can access resources by both logical name and physical
name. Applications using logical name is portable across all compliant
appservers (e.g., Jboss, weblogic, websphere, etc). Applications using
physical names are not portable and may not work in other appservers.

For a resource created in admin console or admin gui, you can access
with either physical name, or logical name if the reference has been
properly configured in your application. Think of logical name as
another level of indirection that adds more flexibility.

Your static lookup method getSomething() will not work if you call it
before the EJB is fully initialized. Say if you call it from a static
initializer of the bean class, or from the constructor, the EJB is not
ready for JNDI service. How do you call this function (more code, please)?

As usual, you will need something like these in ejb-jar.xml, if you want
to avoid injection:
<resource-ref>
    <res-ref-name>something</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <mapped-name>something</mapped-name>
</resource-ref>

-cheng