A walkthough about session beans in EJB 3

Session Bean

  1. Session beans are specifically meant to handle client requests
  2. Session beans support both Java Remote Method Invocation (RMI)-based native and Simple Object Access Protocol (SOAP)-based web services remote access.
  3. Supports Transaction and security management
  4. Provides Timer services and interceptors
  5. Provides remoting and web services

Examples Of  Sesson Bean

  1. If session bean in a human resources application that creates a new employee and assigns the employee to a particular payroll department
  2. Contents of a shopping cart in an e-commerce application manages by Session Bean
  3. It can manage transaction in any banking application

Types Of Session Bean

  1. Stateless
  2. Statefull

StatelessSession Bean

  1. A stateless session bean does not maintain a conversational state with the client
  2.  When a client invokes the methods of a stateless bean, the  instance of bean variables may contain a state specific to that client only for the duration of a method invocation.
     Once the method is finished, the client-specific state should not be retained i.e. the EJB container destroys a stateless session bean.
  3. stateless session beans can support multiple clients, they provide the better scalability for applications that require large numbers of clients

StateFull Session Bean

  1. A stateful session bean retains its state across multiple method invocations made by the same client.
  2. The state of a client bean is retained for the duration of the client-bean session.
  3. Once the client removes the bean or terminates, the session ends and the state disappears.