A walkthough about session beans in EJB 3
- Session beans are specifically meant to handle client requests
- Session beans support both Java Remote Method Invocation (RMI)-based native and Simple Object Access Protocol (SOAP)-based web services remote access.
- Supports Transaction and security management
- Provides Timer services and interceptors
- Provides remoting and web services
Examples Of Sesson Bean
- If session bean in a human resources application that creates a new employee and assigns the employee to a particular payroll department
- Contents of a shopping cart in an e-commerce application manages by Session Bean
- It can manage transaction in any banking application
Types Of Session Bean
- A stateless session bean does not maintain a conversational state with the client
- 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.
- stateless session beans can support multiple clients, they provide the better scalability for applications that require large numbers of clients
StateFull Session Bean
- A stateful session bean retains its state across multiple method invocations made by the same client.
- The state of a client bean is retained for the duration of the client-bean session.
- Once the client removes the bean or terminates, the session ends and the state disappears.