Friday, March 02, 2007

Customizing JNDI name for Session beans

Every vendor provides its own way of registering Session bean interfaces into their global JNDI tree. If you care about portability then you should NOT depend upon the global JNDI name and use the ref-name by using ejb-ref or ejb-local-ref and lookup the EJB from environment naming context using java:comp/env/<ref-name>. However many have their own reasons not to use the standard convention and use the vendor specific JNDI name.

If you are such a soul and want to customize the global JNDI name for a session bean in OC4J you can package an orion-ejb-jar.xml and specify location attribute (for remote interface) and local-location (for local interface) as follows:

<session-deployment location="PlaceOrderBean" name="PlaceOrder"></SESSION-DEPLOYMENT>

Note that OC4J uses the ejb-name element in the ejb-jar.xml or name parameter in @Stateless or @Stateful annotations as the default JNDI name for the remote interface.

If you are using EJB 3 and annotation fanatic then you can use either @StatelessDeployment or @StatefulDeployment annotation to specify the JNDI names as follows:

@StatefulDeployment(location="PlaceOrder",
localLocation="PlaceOrderBeanLocal")

Even if I want you to marry to our platform and use the global JNDI name so that your migration becomes difficult but I will advise against using global JNDI names and recommend that you to use ejb-ref for portability reasons.

No comments: