• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

JNDI Lookup/ejb-jar.xml to find an another ejb

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

When a EJB wants to talk to an another bean,we always do a JNDI lookup to get the Bean's Home Interface,then the home's create to get the componenet interface.
In the deployment descriptor do we need to specify the <ejb-ref> tag inorder for a EJB to talk to another EJB.Is this required only when the two ejb's have seperate DD's.If the two EJB's are defined in the same ejb-jar.xml then we wouldn't need the <ejb-ref> tag?Am I right?

Why do we need this ejb-ref tag at all,when we always locate a Bean using the JNDI lookup?

Any insights is really appreciated.

Thanks
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SU,


In the deployment descriptor do we need to specify the <ejb-ref> tag inorder for a EJB to talk to another EJB.Is this required only when the two ejb's have seperate DD's.If the two EJB's are defined in the same ejb-jar.xml then we wouldn't need the <ejb-ref> tag?Am I right?


Actually you�re not. They are not required but they are good practice though. Without ejb references, EJB components will be highly coupled enforcing the code in your EJBs to know the JNDI name for all referenced EJBs, in order to do the lookup. If later on the referenced beans' JNDI name will change (as an example consider versioning where the bean could have names like /ejb/1.0/AccountHome, which might change from version to version), then you have to change your code accordingly, recompile and redeploy the beans, etc. Sure you might have the JNDI names configuration driven, but ejb reference on the other hand will always be the best approach.
Regards.
 
SU Lingam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.

Well the value of the <ejb-ref> tag corresponds to the ejb-name of a Bean.Isn't?Well it's tightly coupled even then!!If the ejb-name of a bean
changes then you still have to change the ejb-ref??
The purpose of the ejb-ref tag shud have been I guess to be able to directly access the Home without going thru a lookup process.With the JNDI
Name we can go ahead directly accessing the Bean's Home,without having to
specify <ejb-ref> blocks.If the bean references 6-7 beans,the DD then becomes fairly complex and you still need to do the JNDI lookup for all the beans.That gives me the thinking why go for ejb-ref tags.

Thanks
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SU,


Well the value of the <ejb-ref> tag corresponds to the ejb-name of a Bean.Isn't?


That�s correct.


Well it's tightly coupled even then!!If the ejb-name of a bean
changes then you still have to change the ejb-ref??


Not quite. The ejb-name of the bean is just a symbolic name and doesn�t bear the same naming restrictions like the jndi name. Moreover it shouldn�t change at all during the entire application lifetime. I personally cannot see any good reason why you should change the ejb-name. Can you think of any?


The purpose of the ejb-ref tag shud have been I guess to be able to directly access the Home without going thru a lookup process.


I�m happy you raised this issue and I�ll go even further saying that EJBs should not be looked-up to jndi at all. However in order to understand the importance of ejb-refs I�ll advice you to search the net for the Environment Naming Context (ENC).


With the JNDI
Name we can go ahead directly accessing the Bean's Home,without having to
specify <ejb-ref> blocks.


Please understand the difference. jndi names are not easy to manage and they might change over time much more often than the ejb-names (which shouldn�t change at all). If you�d like we can go through the versioning example in more detail and try to understand the issue from a maintenance point of view, when ejbs are accessed through references vs jndi names.


If the bean references 6-7 beans,the DD then becomes fairly complex and you still need to do the JNDI lookup for all the beans.That gives me the thinking why go for ejb-ref tags.


You�re very right here and this is a common drawback of using ejb references. This also might give you the reason why ejb-names should not change at all. However it is a fait trade if you�d consider the headache to maintain a system where the jndi names of your beans changes over time. On the other hand using tools like EJBGen or XDoclet might help you managing the references within your descriptors.
Regards.
 
SU Lingam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi VT,

>>Please understand the difference. jndi names are not easy to manage and they might change over time much more often than the ejb-names (which shouldn�t change at all). If you�d like we can go through the versioning example in more detail and try to understand the issue from a maintenance point of view, when ejbs are accessed through references vs jndi names.

Yes..I would definitely would like to gain some perspective on this.Let's go thru an example.

Thanks for your insights.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SU,

For simplicity let�s suppose we have deployed the application as an ear that contains at least an entity bean. The Account ejb will be accessed by other j2ee components, which could be either other ejbs, jsps, or servlets. Let�s take a look at the configuration:

In this approach the client (jsp, servlet, other ejb, etc) will lookup the Account bean like this:

The same could be achieved doing a global lookup:

So far so good and both solutions seems to be pretty identical. Morover the global lookup doesn�t require any extra configuration stuff. Now imagine that after three months a new release of the application is required. This time the Account bean will be upgraded and a new version 1.1 of this ejbs needs to be deployed with the new ear. Also let�s suppose that the requirements enforce deploying both versions to the same cluster (as you know beans cannot be bound to the jndi tree with the same names and this is a common technique for versioning ejbs). Hence the Account bean will be reconfigured as followed:

If your clients looked up the bean using the references then your code is safe and no changes are required. As you might see the first lookup will always work. Using global jndi names on the other hand will enforce changing the client code as well.
I hope this will help.
Regards.
 
SU Lingam
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really appreciate, you taking your time explaining abt <ejb-ref> tag over JNDI tag.Sure did gain some perspective...

Thanks
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're most welcome SU
 
reply
    Bookmark Topic Watch Topic
  • New Topic