• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why do we need ejb-references ??

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all,

I read everywhere that if I want to get access to a local interface from a bean I must declare a reference.

The problem is that I haven't found anywhere the explanation why I need to do this. Why a bean can't just get access to other beans by JNDI lookups ?

kind regards

k.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karol,
Welcome to JavaRanch!

To some extent, we need the references because the spec says so. As a result, the EJB containers require you to use references.

The reason that the spec says so is to provide a level of indirection between the JNDI and the actual resource. This is true for DataSources and other resources as well.
 
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 Karol,

EJB references are good practice because they help to achieve location transparency. In a nutshel your bean's jndi name could change and as an example consider versioning: a new version of the bean could be deployed with another jndi name. If you use ejb references than your configuration don't need to change at all. If your app would look up the bean based on its jndi name, than your configuration must change accordingly. However they are not mandatory and you can lokup your remote as well as local ejb home objects if you like.
Regards.
 
Karol Oslowski
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!

Your answers have clarified this issue to me.

kind regards
 
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 very welcome Karol, I'm glad I could help
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The reason that the spec says so is to provide a level of indirection between the JNDI and the actual resource. This is true for DataSources and other resources as well.


Let's understand the reason for this. The Bean Provider writes reusable components which can be deployed anywhere and by anyone. When he needs to do a JNDI lookup on a DataSource, he does not know the real JNDI name of the database let alone the real name of the database. So, he invents a JNDI name to use in his code.

However, he also declares the same fake JNDI name in the DD.

The Application Deployer will then map the fake JNDI name to the real JNDI name (let's call it CustDatabse) under which the DataSource is registered using a vendor-supplied tool. The System Administrator will then configure the database (let's say its real name is CustomerData) into the server and gives it a JNDI name.

So, the use of fake JNDI names and subsequent mapping to real names is fundamentally important to the objective of WODA (write once deploy anywhere).
 
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic