Creating a Session Bean with the EJB Builder

Creating a Session Bean with the EJB Builder follows these steps:

  1. Creating the Session Bean
  2. Coding generated Session Bean methods
  3. Creating a Business Method

Creating the Session Bean

To create the session bean:

  1. Create a directory for the session bean on your local file system.
  2. In the IDE, mount the new local directory.
  3. Choose File -> Mount Filesystem and use the New wizard to find and select the new local directory. The directory appears as a new node in the IDE Explorer's Filesystem Tab pane.

  4. Create a new Java Package.
  5. Right-click the new filesystem, choose New -> Java Package, and enter a name for the new package. The package appears in the IDE Explorer's Filesystem Tab pane, expanded under the new local directory node.

  6. Configure the session bean.
  7. Right-click the new Java package node and choose New -> J2EE -> Session EJB. In the Session Bean Name and Properties pane of the New wizard, enter a name for the bean in the EJB name field, and select the following options:

    Field Name Value
    State Stateless
    Transaction Type Container-Managed
    Component Interfaces Remote Interface Only (Default)

Coding generated Session Bean Methods

For a session bean, the bean class must implement the javax.ejb.SessionBean interface, and it must have at least one create(...) method declared as public and returning void. The required methods are created by the IDE, and you will put output statements that show when the methods are invoked.

To update methods:

  1. Double-click the new bean node.
  2. The source editor shows the .java file.

  3. Implement methods for the Session EJB.
  4. These should include: ejbActivate(), ejbPassivate(), ejbRemove(), and ejbCreate().

  5. In the IDE, choose File -> Save All.
  6. This will save the session bean that you have created so far.

    NOTE - In many cases, your work is saved automatically by the IDE. However, use File -> Save All whenever you wish to leave the guide for a time or want to make sure all your work is saved. You may also use the Save and Save Sll buttons in the toolbar which become enabled when there is work to be saved.

Creating a Business Method

Once you have created a default create method and life-cycle methods and completed the coding of these methods, the new session bean requires a business method to run business tasks for the client.

To create the business method:

  1. Right-click the session bean name (EJB) node and choose Add Business Method.
  2. The Add New Business Method dialog box appears.

  3. Enter a name for the business method in the Name field and choose a Return Type.
  4. Click Okay. The new business method is added to the session bean and its method signature is added to the bean's remote interface.

  5. View the business method in the source editor.
  6. Expand the new session bean (EJB) node and its Business Methods node. Double-click the new business method node. The source editor shows the method.

  7. Add the business method body.
  8. public return type business method name() {
        ...
        method body
        ...
    }
    
  9. Add any necessary import statements at the top of the file.
  10. Validate the business method.
  11. Right-click the new session bean (EJB) logical node and choose Validate EJB.

    TIP - The EJB Builder contains a custom compiler that validates your enterprise beans against the Enterprise JavaBeans Specification. When you select an enterprise bean node, right-click it, and choose Validate EJB, the IDE compiles the bean and then immediately validates it.



Legal Notices