SET AS HOME PAGE

ADD TO FAVORITES / BOOKMARK THIS WEBSITE (More Details)

Introduction

Servlet

Jsp

Security

Enterprise Beans

Contact Us


Creating Bean-Managed Persistence (BMP) Entity Beans (Continue...)

 Introduction

The process of creating a BMP entity bean consists of:
  • Configuring the database
  • Creating a set of enterprise bean class files

A BMP entity bean consists of the following files:
  • BMP entity bean remote or local interface
  • BMP entity bean remote home or local home interface
  • BMP entity bean class
Types of Enterprise Beans are
  • Session Beans
    1. Stateless Session Beans
    2. Stateful Session Beans
  • Entity Beans
    1.  Bean Managed Persistent (BMP) Entity Beans
    2. Container Managed Persistent (CMP) Entity Beans
  • Message-Driven Bean

 Creating a BMP Entity Bean Remote Interface

  • An entity bean remote interface declares the business methods used by a client.
  • The remote interface consists of a set of methods corresponding to the methods that are present in the entity bean class.
  • The signatures of the methods in the remote interface should be the same as the corresponding methods in the entity bean class.
  • The remote interface extends the javax.ejb.EJBObject interface and consists of the declaration of the business methods.
  • The throw clause of the methods that are declared in the remote interface should include the exception, java.rmi.RemoteException.
 Creating a BMP Entity Bean Local Interface

  • A local client uses the local interface to call the entity bean.
  • The local interface of an entity bean extends the javax.ejb.EJBLocalObject interface.
  • The methods that are declared in the local interface need to have the corresponding methods with the same signature in the entity bean class.
 Creating a BMP Entity Bean Remote Home Interface

  • The remote home interface of an entity bean includes the methods that enable a client to create, locate, or destroy the entity bean.
  • The methods in the remote home interface should have a corresponding set of methods in the entity bean class.
  • The signatures of the methods in the remote home interface should be the same as the corresponding methods in the entity bean class.
  • The remote home interface of a BMP entity extends the javax.ejb.EJBHome interface and includes the findByPrimaryKey() method.
  • The methods in the remote home interface should throw the exception, java.rmi.RemoteException.
 Creating a BMP Entity Bean Local Home Interface

  • The local home interface of an entity bean includes the methods to create, locate, and destroy an entity bean.
  • The methods in the local home interface need to have the corresponding methods in the entity bean class with the same signature.
  • The local home interface of an entity bean extends the javax.ejb.EJBHome interface.
 Creating a BMP Entity Bean Class

  • The entity bean class implements the life cycle methods used by EJB container to control the life cycle of an entity bean.
  • The entity bean class implements the business methods declared in the entity bean remote interface.
  • The entity bean class can only be defined as public and implements the business methods defined in the component interfaces of an entity bean.
  • The entity bean class implements the javax.ejb.EntityBean interface.
  • The entity bean class includes a default constructor that does not have any arguments.
  • The entity bean class should implement the ejbCreate(), ejbPostCreate(), ejbFind(), and ejbHome() methods.
 Accessing BMP Entity Bean

  • A client accesses a BMP entity bean’s business methods using the references of entity bean’s home and remote interfaces.
  • Both, Web clients and Application clients can access a BMP entity bean.
  • The steps to access a BMP entity bean are:
    1. Locates a BMP entity bean in the J2EE 1.4 Application Server.
    2. Retrieves references of the BMP entity bean home and remote interfaces.
 Locating a BMP entity Bean

To locate a BMP entity bean, the client performs the following steps:
  1. Uses the InitialContext interface of JNDI to create an initial naming context.
    InitialContext ctx = new InitialContext();

  2. Uses the lookup() method to locates the home object of the deployed BMP entity bean.
    Object ref = ctx.lookup("JNDI name");
 Retrieving References of BMP Entity Bean Interfaces

  • After locating the BMP entity bean, a client retrieves references of the BMP entity bean home and remote interfaces to invoke an entity bean’s business methods.

  • The narrow() method of the PortableRemoteObject interface is used to retrieve the reference of a BMP entity bean remote home interface.
    You can use the following statement to retrieve a reference of BMP entity bean remote home:
    BMPentityRemoteHome bmpremotehome = (BMPentityremoteHome)PortableRemoteObject.narrow(ref, BMPentityRemoteHome.class);

  • Local clients need to use lookup() method of the InitialContext interface to retrieve a reference of a BMP entity bean local home interface.
    You can use the following statement to locate and retrieve a reference to BMP entity bean local home interface:
    BMPentityLocalHome bmplocalhome = (BMPentityLocalHome)ctx.lookup("JNDIname");

  • A client invokes the create() method in the BMP entity bean home interface for retrieving a reference to BMP entity bean remote interface.
    You can use the following code snippet to retrieve a reference to the remote interface of a BMP entity bean:
    BMPentityRemote bmpremote = bmpremotehome.create(datatype param1, datatype param2);

  • A local client invokes the create() method to retrieve a reference to a BMP entity bean local interface.
    You can use the following code snippet to retrieve a reference of the local interface of a BMP entity bean:
    BMPentityLocal bmplocal = bmplocalhome.create(datatype param1, datatype param2);

 Click for Next Topic
<- PREVIOUSNEXT ->