my dog learned polymorphism
The moose likes EJB and other Java EE Technologies and the fly likes Why use beanName() OR mappedName() ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Why use beanName() OR mappedName() ?" Watch "Why use beanName() OR mappedName() ?" New topic

Why use beanName() OR mappedName() ?

Anirudh Gupta
Ranch Hand

Joined: Dec 08, 2010
Posts: 49

Why is there a need for attributes like beanName() OR mappedName() when name() attribute is already available as per the EJB3.1 specification?
According to EJB O'Reily,
1. "The name() attribute refers to what the JNDI ENC name will be for the referenced EJB. This name is relative to the java:comp/env context."
2. "The beanName() is the EJB name of the EJB referenced. It is equal to either the value you specify in the or
annotation or the value you put in the <ejb-name> field in the XML deployment descriptor."
3. "The mappedName() attribute is a placeholder for a vendor-specific identifier. This identifier may be a key into the vendor’s global registry."

In addition to the above the lookup() attribute adds more to the confusion.
Can someone clarify with an example please?

Davide Crudo
Ranch Hand

Joined: Sep 08, 2009
Posts: 62

is a friendly name. Imagine you have the following:

you can just refer to the bean with "manager" instead of the full class name.

mappedName as you stated is vendor specific. So its behaviour depends on the container you will be using.
in Glassfish is used to assign a global name in JNDI

for beanName you can check this thread (i've never used it myself):

Thread Link

You use the Lookup when you need to locate a bean looking in the context.

For instance, check the section related to the RMI (Calling an EJB remotely). In which case you will need
to ask the remote server to look into the context and find your bean.

Normally, when working on the local server with local beans, I don't ask the context to find beans ,
i just inject them and let EJB taking care of finding them.


I agree. Here's the link:
subject: Why use beanName() OR mappedName() ?
It's not a secret anymore!