Bean Session in Java

Bean session in java enterprise application.

Bean session in Java

Enterprise bean in Java is a matter of subject that has bothered many beginner programmers. There are three types of Enterprise beans in java

  • Bean session
  • Bean Entity
  • Bean message driven

Let us discuss more about bean session and what it requires to code a session bean. Enterprise bean is packaged in a .war file while the enterprise module is packaged in .jar file.

Bean session coding will require two interfaces Home and Component.

Home interface may be remote or local and extends EJBHome class. Have a look at an example below:

Import javax.ejb.*;

Import java.rmi.*;

Public interface HomeExample extends EJBHome

{

            ComponentExample void create() throws RemoteException;

}

Component interface can be remote or local and extends EJBObject

Import javax.ejb.*;

Import java.rmi.*;

Public interface ComponentExample extends EJBObject

{

            Public void business() throws RemoteException;

}

Import javax.ejb.*;

Public class BeanSession extends Session

{

            Public void ejbCreate()

            {

            }

            Public void ejbRemove()

            {

            }

            Public void ejbActivate()

            {

            }

            Public void ejbPassivate()

            {

            }

            Public void setSessionContext(SessionContext sc)

            {

            }

            Public void business()

            {

            }

}

Other than interfaces the main bean implementation class BeanSession is shown above and it requires you to implement your business method, infrastructure methods and bean life cycle methods.

In component interface business method of the bean class is declared. The call to the bean class takes place through home interface where create method is called which in turns calls the ejbCeate method of the bean class. The component interface will allow client to call the business method of bean class by declaring business methods.

You will also require clients to call the bean session for your enterprise application and it can be servlet or java application.

Leave Your Response