@ejbgen:ejb-local-ref Annotation

Maps a JNDI reference used by a bean to the referenced bean's local interfaces.

Scope

Class tag on the EJB that references the other EJB through its local interfaces.

Syntax

@ejbgen:ejb-local-ref

[home="LocalHomeInterFace"]

[id="TagID"]

[jndi-name="JNDIName"]

[link="EJBName"]

[local="LocalInterface"]

[name="ReferenceName"]

[type="Entity/Session"]

Attributes

home

Optional. Specifies the local home interface of the referenced EJB.

id

Optional. Specifies the ID of the tag. For more information, see EJBGen Tag Inheritance.

jndi-name

Optional. Specifies the local JNDI name of the referenced EJB.

link

Optional. Specifies the (descriptive) name of the referenced bean, that is the name given in the ejb-name property located in the General Settings section of the Property Editor.

local

Optional. Specifies the local (business) interface of the referenced EJB.

name

Optional. The name used to reference the other bean.

type

Optional. Specifies the EJB type of the referenced bean. Valid values are Entity and Session.

Remarks

To use this tag, specify its attributes in one of the following ways:

Example

In this example, a Band EJB references a Recording EJB. Here is the partial code for the Band EJB, with the reference definition and use shown in bold:

/**
 * @ejbgen:ejb-local-ref link="Recording" 
 * ...
 */
abstract public class BandBean extends GenericEntityBean implements EntityBean
{
  ...
  private RecordingHome recordingHome;


  public void setEntityContext(EntityContext c) {
      ctx = c;
      try {
         javax.naming.Context ic = new InitialContext();
         recordingHome = (RecordingHome)ic.lookup("java:/comp/env/ejb/Recording"); 
      }
      catch(Exception e) {
         System.out.println("Unable to obtain RecordingHome: " + e.getMessage());
      }
  }
  ...
}

The name of the Recording bean is given in the definition of that bean:

/**
 * @ejbgen:entity prim-key-class="bands.RecordingBeanPK" 
 *   ejb-name = "Recording"
 *   data-source-name="cgSampleDataSource"
 *   table-name="recording_Sample"
 *   abstract-schema-name = "Recording"
 *
 * ...
*/
abstract public class RecordingBean extends GenericEntityBean implements EntityBean
{
   ...
}

The Band bean defines the local reference to the Recording bean by specifying the Recording bean's name in the link attribute. It uses this information to locate and reference the Recording bean via the InitialContext's lookup method. To learn more about JNDI naming, see the tutorial Getting Started: Enterprise JavaBeans. To see an example of a local reference tag that specifies name, jndi-name, home, local, and type, see @ejbgen:ejb-ref Annotation.

Related Topics

@ejbgen:ejb-ref Annotation

@ejbgen:jndi-name Annotation

@ejbgen:file-generation Annotation

How Do I: Add a Relation to an Entity Bean?

Tutorial: Enterprise JavaBeans