Creating a Session Bean with the EJB Builder follows these steps:
To create the session bean:
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.
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.
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) |
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:
The source editor shows the .java
file.
These should include: ejbActivate()
, ejbPassivate()
, ejbRemove()
, and
ejbCreate()
.
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.
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:
The Add New Business Method dialog box appears.
Click Okay. The new business method is added to the session bean and its method signature is added to the bean's remote interface.
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.
public return type business method name() { ... method body ... }
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.