Memorizing the EJB-related DD tags

This exam is about web components, not business components (although in the Patterns chapter, you’ll see a few things about business components). But if you’re deploying a J2EE app, complete with Enterprise JavaBeans (EJBs) in the business tier, some of your web components will probably need to lookup and access the enterprise beans. If you’re deploying an app in a full J2EE-compliant Container (one that has an EJB Container as well), you can define references to EJBs in the DD. You don’t have to know anything about EJBs for this exam, other than what you declare in the DD, so we won’t waste your time explaining it here.[11]

Reference to a local bean

image with no caption
image with no caption

A LOCAL bean means the client (in this case, a servlet) and the bean must be running in the same JVM.

Reference to a remote bean

<ejb-ref>
   <ejb-ref-name>ejb/LocalCustomer</ejb-ref-name>
   <ejb-ref-type>Entity</ejb-ref-type>
   <home>com.wickedlysmart.CustomerHome</home>
   <remote>com.wickedlysmart.Customer</remote>
</ejb-ref>
image with no caption

A REMOTE bean means the client (in this case, a servlet) and the bean can be running in different JVMs (possibly on different physical machines as well).

Note

(Optional sub-elements for both tags include <description> and <ejb-link>, but you don’t need to know that for the exam.)

Note

The LOCAL and REMOTE tags are inconsistent!

Both the local and remote bean DD tags have two elements that are the same:

The <ejb-ref-name> that lists the logical lookup name you’ll use in code to perform a JNDI lookup on an enterprise bean’s home interface. (Don’t worry if you haven’t used EJBs before and don’t know what that last sentence means—you don’t need EJB knowledge for this exam.)

The <ejb-ref-type> describes whether this is an Entity or Session bean. Those two elements, the lookup name and the bean type, don’t depend on whether the bean is local (running in the same JVM as the web component), or remote (potentially running in a different JVM).

But... look at the other elements starting with the outer tags: <ejb-local-ref> and <ejb-ref>. You might be tempted to think that it’s:

image with no caption

In other words, the local reference says it’s local, but the remote reference does NOT include the word “remote” in its tag element name. Why? Because at the time <ejb-ref> was first defined, there was no such thing as “local” EJBs. Since ALL enterprise beans were “remote”, there was no need to differentiate between local and remote, so no need to put “remote” in the name of the tag.

This also explains the OTHER tag naming inconsistency— the name of the tag for the bean’s home interface. A local bean uses:

image with no caption

For remote beans, it’s just:

<home>



[11] But if you’re interested in EJB, there’s this really good book...

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset