Sponsered Links
Categories
Sponsered Links

Introduction to EJB

 

EJB stands for Enterprise JavaBeans. Enterprise JavaBeans (EJB) is a managed, server-side component architecture for modular construction of enterprise applications. In a J2EE application, EJB contains the application's business logic and live business data. Although it is possible to use standard Java objects to contain your business logic and business data, using EJB addresses many of the issues you would find by using simple Java objects, such as scalability, lifecycle management, and state management.

J2EE and EJB

A J2EE servers worked as a "container". J2EE divides the deployment in two separate containers, one is JSP and Servlets and another is EJB. The container for EJB is called the "EJB container". These containers can be run in separate JVM or in the same one.

Overview of EJB and Lifecycle

The container is responsible for loading, activating, and in general maintaining the "life-cycle" of objects it provides. EJB have a fairly complex life-cycle. There are several kinds of EJB:

  • Session Beans: These may be either stateful or stateless, and are primarily used to encapsulate business logic, carry out tasks on behalf of a client, and act as controllers or managers for other beans.

interface
SessionBean
extends javax.ejb.EnterpriseBean

ejbActivate()
    throws javax.ejb.EJBException, java.rmi.RemoteException

ejbPassivate()
    throws javax.ejb.EJBException, java.rmi.RemoteException

ejbRemove()
    throws javax.ejb.EJBException, java.rmi.RemoteException

setSessionContext(javax.ejb.SessionContext)
    throws javax.ejb.EJBException, java.rmi.RemoteException   

Figure: The javax.ejb.SessionBean interface

  • Entity Beans: Entity beans represent persistent objects or business concepts that exist outside a specific application's lifetime. They are typically stored in a relational database. Entity beans can be developed using bean-managed persistence, which is implemented by the developer, or container-managed persistence, implemented by the container.

interface
EntityBean
extends javax.ejb.EnterpriseBean

ejbActivate()
    throws javax.ejb.EJBException, java.rmi.RemoteException

ejbLoad()
    throws javax.ejb.EJBException, java.rmi.RemoteException

ejbPassivate()
    throws javax.ejb.EJBException, java.rmi.RemoteException

ejbRemove()
    throws javax.ejb.EJBException, java.rmi.RemoteException

ejbStore()
    throws javax.ejb.EJBException, java.rmi.RemoteException

setEntityContext(javax.ejb.EntityContext)
    throws javax.ejb.EJBException, java.rmi.RemoteException

unsetEntityContext()
    throws javax.ejb.EJBException, java.rmi.RemoteException

  • Message-Driven Beans: Message-driven beans listen asynchronously for Java Message Service (JMS) messages from any client or component and are used for loosely coupled, typically batch processing.

interface
MessageDrivenBean
extends javax.ejb.EnterpriseBean

ejbRemove()
    throws javax.ejb.EJBException, java.rmi.RemoteException

setMessageDrivenContext(javax.ejb.MessageDrivenContext)
    throws javax.ejb.EJBException, java.rmi.RemoteException

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved