Creating EJB 1.1 Beans
This chapter describes how to create entity beans having version 1.1, using Bean Wizard. Entity beans with bean managed persistence requires ejbHome, ejbFind, and business methods, all of which can be created using the Bean Wizard.
Start Bean Wizard using Tools > Bean Wizard from the main menu. In the following sections, a brief description of the steps involved in creating these beans is provided.
Refer the relevant chapters for detailed description of each of the panels in the Bean Wizard.
Selecting Modules
EJB 1.1 Beans can be created only in EJB 1.1 or Java Modules. While creating a Desk, select the template as "EJB 1.1 Desk". This template comprises a EJB 1.1 Module, a JAR and a WAR. You could also create a these modules by right clicking on the Desk Root and selecting a new folder type as a Java Module or EJB 1.1 Module.
Creating Session Beans
Session Beans are short lived components that are transaction aware and are deleted when the container crashes. They always execute on behalf of a single client, and also updates shared data in an underlying database. Session beans are of two types - Stateful, and Stateless.
The following are the panels that appear, while creating Session beans in the Expert mode:
- Defining Beans This panel is used to define the type of bean to be created. The bean can be selected as either Session - Stateless, or Session - Stateful
- Define Create Methods This panel appears only when the type of bean selected is Session - Stateful, and the transaction Type as Bean Managed. This is used to define create methods of the bean
- Define Business Methods This panel is used to define the skeleton code of the business methods in the bean
- Select Bean Interfaces This panel is used to define the home and remote interface names, that are to be created along with the bean
- Methods to Publish In Interface(s) - Home This panel appears only when the selected bean was of the type, Session - Stateful. The selected methods are placed in the home interface, after the bean is created
The home and local home interfaces for the stateless session beans are created automatically as per the ejb specification. The wizard therefore does not bring this panel up for stateless session beans
- Methods to Publish In Interface(s) - Remote This panel displays all the business methods defined earlier, that are to be placed in the Remote interfaces
Creating Entity Beans
An entity bean is a long-lived component that operates on a database on a continuing basis. The Entity Beans need information about
- Data Connections For the beans to persist
- Queries To be used by the finder methods
The following are the panels that appear, while creating Entity beans in the Expert mode:
- Defining Beans This panel is used to define the type of bean to be created. The bean can be selected as either Entity - Bean Managed, or Entity - Container Managed.
- Defining Bean/Container Managed Fields (without database) This panel appears when the bean being created does not use an existing database. Tables in the database can be created after the bean has been created
- Defining Bean/Container Managed Fields (with database) This panel appears when the bean being created uses an existing database. The option, Use Existing Database should have been checked in the first panel of the Bean Wizard
- Define Create Methods This panel is used to define create methods of the bean
- Define Business Methods This panel is used to define the skeleton code of the business methods in the bean
- Define Finder Methods This panel is used to define the skeleton code for the finder methods of entity beans. The finder methods created are always prefixed with ejbFind before the method name.
- Select Bean Interfaces This panel is used to define the home and remote interface names, that are to be created along with the bean
- Methods to Publish In Interface(s) - Home This panel is used to check the home interfaces for the finder methods created previously. The selected methods are placed in the home interface, after the bean is created
- Methods to Publish In Interface(s) - Remote This panel displays all the get and set methods defined for the CMP beans and also the business methods for BMP and CMP beans, that were defined earlier. The checked methods are then placed in the Remote interfaces