This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Which one is the recommended?? Because I could get wrong in the exam. And in the enthuware mock exam for EJB, They recommend that I should use lookup attribute for java portable jndi (java:global, java:module, and java:app) and not for getting a reference of a Queue.
Thanks for the information @Himai Minh and the link.
I get it. The correct (because is the portable way) way for getting a Queue destination is using the lookup attribute.
mappedBy will works in some application server and in other it will not work.
The name for getting a Queue destination will works in some application server like Glassfish. In glassfish if you only supply the name attribute and that name is the same of a jndi direction of a Queue destination, glassfish will use it.
Joined: Jul 29, 2012
Hi, Edwin and everyone.
I am reading EJB in Action. On p.133,
@Resource annotation elements:
name - besides performing an injection, the @Resource annotation implicitly creates a binding referring to the injected resource in the java:comp namespace. This is primarily done for backward compatibility. This attribute allows you to specify the name that is used for the implicit binding. This is equivalent t the <res-ref-name> element in deployment descriptors used extensively in EJB2.
My comment : I guess @Resource(name = ...) is not commonly used with EJB 3.1 unless it is used for backward compatibility with EJB 2.0.
lookup - This is the actual JNDI lookup name of the resource to be injected. This is likely the attribute you will use the most.
My comment: I guess it is always the right choice to use lookup for looking up the JNDI name of a queue, DataSource, Session and etc.
Note that the injected session context isn't stored anywhere in JNDI. In fact, it would be incorrect to try to specify JNDI lookup parameters in this case at all, and servers will probably ignore the element if specified.
mappedName - A vendor-name for the bean.
Example on p.21 of EJB 3.1 Cookbook by Richard Reese
The connection factory was created by the server GlassFish in this case, with the name jms/SalutationQueueFactory which is of type QueueConnectionFactory.
@Resource (mappedName ="jms/SalutationQueueFactory")
private QueueConnectionFactory queueConnectionFactory;
The queue is of type javax.jms.Queue and used the name jms/SalutationQueue as defined within the server. @Resource annotation was used again to inject this resource.
private Queue queue;
The EJB 3.0 Specification defines mappedName as a "product-specific name that the session bean should be mapped to." Often, application server use mappedName to map a session bean to a global JNDI name. The EJB 3.1 specification sort of deprecates the mappedName element and introduces the concept of "portable global JNDI name".
These are just my comments. Correct me if I am wrong.
Do you mean this story:
inject a Destination object from the application server and this Destination object's name is mapped to OrderBillingQueue (the one specified by mappedName attribute) in the server.
Once this object is injected and refered by the billingQueue reference, it will be called jms/OrderBillingQueue (the one specified by the name attribute) locally
I believe @Resource (lookup= "java:global/jms/OrderBilingQueue) is more commonly used.
So, is lookkup a replacement of mappedName?
In analogy of Jaikiran's example using a mappedName and name attribute you can have an @Resource with a lookup and a name attribute.
(Example from my notes ch. 7.5.2 name vs. lookup):
You can make a resource in the global JNDI (lookup=”jms/websendqueue”) available under another name (name=“q”) in the bean class.
Joined: Jul 29, 2012
Hi, Frits.Thanks for your reply.
As I read your notes and other materials,
if we have :
I realized lookup = jms/OrderBillingQueue is the name of the resource in the JNDI directory, it is "java:global/jms/OrderBillingQueue" as it is a global JNDI name.
The name = OrderBillingQueue is name referring to this resource for developer to lookup
Or, if we have :
I realized mappedName = jms/OrderBillingQueue is the name of the resource in the specific application server's JNDI directory, it may be "java:global/jms/OrderBillingQueue" if it is a global JNDI name .
The name = OrderBillingQueue is name referring to this resource for developer to look for
Correct me if I am wrong.
subject: Doubt about getting a Queue reference using Resource annotation