• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why use beanName() OR mappedName() ?

 
Anirudh Gupta
Ranch Hand
Posts: 49
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 @Stateless.name() or @Stateful.name()
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Stateless(name="manager")

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.

Regards
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic