Define bean relationships

Use the EJB deployment descriptor editor to specify the relationship between two enterprise beans in your EJB module.

Important: Relationships for EJB 1.1 beans are WebSphere Application Server extensions to the EJB 1.1 specification. Relationships for EJB 2.x beans are part of the EJB 2.x specification. If your project is not targeted to a WebSphere Application Server runtime environment, the editor does not display any EJB 1.1 relationship sections. The two levels of relationships are handled differently from different sections of the deployment descriptor editor.

The EJB deployment descriptor editor generates the appropriate finder methods to support any relationships that you create.

When you define a relationship from one CMP bean to another, extra CMP fields based on the key fields from the referencing CMP bean are added to the owning CMP bean of the forward referencing role (Foreign Key check box is selected on the owning CMP bean).

For example, Company has a 1:many relationship to Employee with roles company and employees respectively. The company role is forward and the Company CMP bean has key fields named "companyID" and "companyName". The CMP fields that are automatically added to the Employee bean are "company_companyID" and "company_companyName". These fields are hidden in the EJB editor because they are fields that were added to support the "employee" relationship role. Problems would arise if these CMP fields were removed from the ejb-jar.xml file while the relationship still existed.

When a relationship is created, additional classes are created to support the runtime in maintaining the links between these two beans. Also, additional methods will be generated into the Home, Remote, and Bean classes of both enterprise beans. You will see compile errors in the EJB deployment descriptor editor when a relationship is first created because the generated Link classes need to be compiled. You will see the actual code in these files but the changes in the Home, Remote, and Bean classes have not yet been compiled. This will not take place until the project is built, which usually happens automatically when the EJB deployment descriptor editor or the EJB editor is saved. Therefore, you will not see compile errors until the editor is saved.

Note: If a relationship exists between one or more CMP beans, changing the key shape of one CMP may result in the related CMPs being regenerated.

If you intend to access the enterprise beans from a Java application, add the following JAR files to the class path:

  • ivjejb35.jar

  • vaprt.jar

For example, if you are using relationships and call a relationship method on the remote interface that returns an enumeration of enterprise beans, the method call will throw an exception unless these JAR files are added to the class path.

 

Related concepts

EJB Deployment Descriptor editor
EJB relationships

 

Related tasks

Creating relationships for EJB 2.x beans