• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mappedName element

 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this mappedName element with many annotations including entity relationship annotations too. I really confused when I see this element. In some examples, it uses a simple String value as mappedName="somthing" and sometimes it uses a JNDI context as mappedName="jms/Queue"

What is mappedName? Why we need to use it? I really confused now

Please can anyone explain this for me, please.
 
prashant k. gupta
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MappedName element is basically for global jndi name.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
prashant k. gupta wrote:MappedName element is basically for global jndi name.


Thanks Prashant,

Then what is the usage of the "name" property?
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Name property is used to specify unique names per jar file. You can use such name for ejb / message destination linking. For example, suppose you have 2 beans in an ejb-jar, both are local. One has the name BeanA, and the other is BeanB. BeanA used BeanB, os it has this annotation on a field:
@EJB private BeanAInterface beanA;
This works fine, but only if there exist one implementatin of BeanAInterface in the jar file. If there exist more, you need to specify the bean name:
@EJB(beanName = "BeanA") private BeanAInterface beanA;
Mapped name can be used to bind a bean based on global JNDI names.

When the name attribute is used in @Resource and others, it means that this particular resource is imported into the environment (java:comp/env) of the bean that uses it under this very name, so that JNDI lookups (for example in the bean's interceptors) can look it up by:
EJBContext.lookup(name);

And from your first post:
In some examples, it uses a simple String value as mappedName="somthing" and sometimes it uses a JNDI context as mappedName="jms/Queue"

It is not true, it _always_ uses a JNDI context, but "jms/Queue" uses a subcontext (as suggsted by the specs), whereas "something" does not. And the difference between mappedName and name is: mappedName uses the global JNDI context, so _any_ application having access to the JNDI server could look this name up, whereas name imports / looks up resources in the component's (ejb's or web components') private java:comp/env context, and only it and its related objects (like interceptors for a given bean) can look it up.

Raf
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic