Creating EJB Session Beans

You can use a wizard to create a session bean and add it to your project.

The session bean wizard helps you create an Enterprise session bean by walking you through the creation process and by providing you with output files that you can use or that you can modify for use with your application.

To create a session bean, complete the following steps:

  1. From the Java™ EE perspective, expand your EJB project in the Project Explorer view.
  2. Right click on the Session Bean icon, and select New > Session Bean from the pop-up menu. The Create Session Bean wizard appears.
  3. Follow the project wizard prompts.

General Information

State type
A session beans are divided in two types: stateless session beans and stateful session beans.
Stateless session beans
A stateless session bean is a collection of related services, each represented by a method; the bean maintains no state from one method invocation to the next. When you invoke a method on a stateless session bean, it executes the method and returns the result without knowing or caring what other requests have gone before or might follow. Stateless session beans have longer lives because they do not maintain any conversational state.
Stateful session beans
A stateful session bean performs tasks on behalf of a client and maintains state related to that client. This state is called conversational state because it represents a continuing conversation between the stateful session bean and the client. Methods invoked on a stateful session bean can write and read data to and from this conversational state, which is shared among all methods in the bean. Stateful session beans have timeout periods.
Business interface
A business interface of a session bean is an ordinary Java interface that contains the business methods for the bean. A reference to a session bean's business interface can be passed as a parameter or as a return value of a business interface method. It contains methods to initialize a session bean's state and to notify the EJB container when the reference is no more needed and can be removed. The business interfaces are two types:
Remote business interface:
The client can run on a different machine or different Java virtual machine than the enterprise bean it accesses and the location of the bean is transparent.
Local business interface:
The client must run on the same Java virtual machine as the bean it accesses and the location of the enterprise bean is not transparent.
Mapped name
Specifies the bean's global JNDI name. The use of mappedName attribute allows you to assign names which you can use to search the EJB bean through the remote client.
Transaction type
The Transaction type field is used to specify whether the transaction is handled by the Container or the Bean.
Home and Components Interfaces
Home and component interfaces are used only for EJB 2.x session beans.
Home interface:
The home interface allows a client to create, remove and find existing instances of enterprise beans.
Component interface:
The component interface allows a client to access the business methods of the enterprise bean.