EJB Introduction
Program. Restrictions
Stateless Session Bean
Stateless ...(Example-1)
Stateful Session Bean
Stateful ... (Example-2)
Entity Beans
BMP Entity Beans
Config. DB (Example-3)
BMP (Example-4)
Bookmark This Site
|
EJB Components And Programming Restrictions
Introduction
|
An entity bean represents a business object in a persistent storage mechanism. Some examples of business objects are customers, orders, and products. In the Application Server, the persistent storage mechanism is a relational database. Typically, each entity bean has an underlying table in a relational database, and each instance of the bean corresponds to a row in that table.
- Types of Enterprise Beans are
-
- Session Beans
- Stateless Session Beans
- Stateful Session Beans
- Entity Beans
- Bean Managed Persistent (BMP) Entity Beans
- Container Managed Persistent (CMP) Entity Beans
- Message-Driven Bean
|
|
The Remote Interface
|
-
Components of an enterprise bean are:
-
Enterprise Bean Class
-
EJB Object
-
Remote Interface
-
Home Object
-
Home Interface
-
Local Interfaces
-
The Enterprise Bean Class
-
The enterprise bean class that contains the methods to implement the business logic of an EJB application.
-
To create an enterprise bean class for a session bean, you need to implement the javax.ejb.SessionBean interface.
-
You need to implement the javax.ejb.EntityBean and javax.ejb.MessageDrivenBean interfaces for creating the enterprise bean class for entity and message-driven beans, respectively.
-
The Remote Interface
-
The remote interface declares the business methods of an enterprise bean, which can be invoked by a client that is stored at a remote JVM.
-
The rules to create a remote interface file are:
-
It should extend the javax.EJBObject interface.
-
It should contain a declaration of all the methods that are accessible to the clients.
-
All the methods that is remotely accessible to client must throw an exception of type java.rmi.RemoteException. This type of exception is raised when a network connection failure occurs.
-
The remote interface inherits following methods from the javax.ejb.EJBObject interface:
-
getEJBHome()
-
getPrimaryKey()
-
remove()
-
getHandle()
-
isIdentical()
-
EJB Object:
-
Provides services, such as transaction support, security, resource management, persistence, and remote accessibility.
-
The Home Interface:
-
Should import the following packages:
-
java.io.Serializable
-
java.rmi.RemoteException
-
javax.ejb.CreateException
-
javax.ejb.EJBHome
-
Should extend the EJBHome interface and its name should not be a keyword in Java.
-
Should contain a create() method whose return type is the same as the type of the remote interface of the enterprise bean. The create() method is responsible for creating a new instance of enterprise bean.
-
Inherits methods from the javax.ejb.EJBHome interface
-
getEJBMetaData()
-
getHomeHandle()
-
remove()
-
EJB Home interface is used to create an EJB object:
-
The Home Object:
-
Enables clients to instantiate an EJB object that is stored in a remote JVM.
-
Performs the following functions:
-
Creating EJB objects
-
Searching for EJB objects
-
Removing EJB objects
-
The Local Interfaces:
-
Are created when the client and the enterprise bean are stored on the same JVM.
-
Are of two types:
-
local interface
-
local home interface
-
Creating the Local Interface
-
Local interface:
-
Contains the declaration of the methods, which are accessible to the clients.
-
Is created by extending the javax.ejb.EJBLocalObject interface.
-
Creating the Local Home Interface
-
Local home interface:
-
Contains the same set of functions as the home interface.
-
Is created by extending the javax.ejb.EJBLocalHome interface.
|
|
Click for Next Topic
|
|
|