EJB

EJB Projects

EJB Project 1

EJB Examples

EJB EXAMPLE

Implementing the Session Bean
Previous Home Next

If you implementing Session bean then using steps are:

  1. The home interfaces for the bean. The home interface defines the create method for your bean.
  2. Remote home interface extends to the javax.ejb.EJBHome package .
  3. Local home interface extends to the javax.ejb.EJBLocalHome package.
  4. Component interfaces for the bean.
  5. Remote interface declares the methods that a client can invoke remotely. It extends javax.ejb.EJBObject.
  6. Local interface declares the methods that a collocated bean can invoke locally. It extends javax.ejb.EJBLocalObject.
  7. Bean implementation includes the following:
  8. Implementation of the business methods that are declared in the component interfaces.
  9. Container callback methods that are inherited from the javax.ejb.SessionBean
  10. EJB methods that match the home interface create methods:
  11. Stateless session beans, provide an ejbCreate method with no parameters.
  12. Stateful session beans, provide an ejbCreate method with parameters matching those of the create method as defined in the home interfaces.

After If All Steps are follows then

To Creating the Home Interfaces

The home interfaces (remote and local) are used to create the bean instance. It's defining the create method for your bean.

And the session bean can defining the create method in the following ways:

The EJB types and this type parameter are shown here:

  1. Stateless Session Bean
  2. Can have only a single create method, with no parameters.

  3. Stateful Session Bean
  4. Can have one or more create methods, each with its own defined parameters.

    For each create method, a corresponding EJB Create method is defined in the bean implementation.

What is the Remote Invocation:

If Any remote client invokes the EJB through its remote interface. Then the clients are invoking to the create method that is declared within the remote home interface. And the container passes the client call to the EJB create methodówith the appropriate parameter signatureówithin the bean implementation. You can use the parameter arguments to initialize the state of the new EJB object.

The remote home interface must extend the javax.ejb.EJBHome interface.

All create methods may throw the following exceptions:

  • javax.ejb.CreateException
  • javax.ejb.EJBException
  • RuntimeException

Home Interface for Session Bean

A Remote home interface for a stateless session bean called Hello Home:

Example:

package hello;
import javax.ejb.*;
import java.rmi.*;
public interface HelloHome extends EJBHome
{
  public Hello create() throws CreateException, RemoteException;
}
What is Local Invocation?

An EJB can be called locally from a client that exists in the same container. Thus, a collocated bean, and JSP, or servlet invoking to the creating method that is declared within the local home interface. The container passes the client call to the ejbCreate methodówith the appropriate parameter signatureówithin the bean implementation. You can use the parameter arguments to initialize the state of the new EJB object.

The local home interface must extend the javax.ejb.EJBLocalHome interface.

All create methods may throw the following exceptions:

  • javax.ejb.CreateException
  • javax.ejb.EJBException
  • RuntimeException

Example: Local Home Interface for Session Bean

A local home interface for a stateless session bean called HelloLocalHome.

package hello;
import javax.ejb.*;
public interface HelloLocalHome extends EJBLocalHome
{
 public HelloLocal create() throws CreateException, EJBException;
}
Previous Home Next