Professional Documents
Culture Documents
Enterprise Javabeans: The Ejb Architecture Specifies The Responsibilities and Interactions Among Ejb Entities
Enterprise Javabeans: The Ejb Architecture Specifies The Responsibilities and Interactions Among Ejb Entities
EJB
1 2
Enterprise JavaBeans
• A specification from JavaSoft
• Enterprise JavaBeans defines a server component
model for the development and deployment of Java
applications based on a multi-tier, distributed object
architecture
• The Enterprise JavaBeans specification defines:
– A container model
– A definition of the services the container needs to
provide to an Enterprise JavaBean, and vice versa
– How a container should manage Enterprise
JavaBeans
3 4
EJB Container
Clients
EJB Server
EJB Server
5 6
1
12/6/2019
EJB Container
EJB Container
EJB Server
EJB Server
7 8
• Client access is controlled by the container in which • Enterprise JavaBeans is a framework for
the enterprise Bean is deployed building and deploying server-side Java
• Clients locates an Enterprise JavaBean through components
Java Naming and Directory Interface (JNDI) • JavaBeans is a framework for client-side Java
• RMI is the standard method for accessing a bean components
over a network
• Conceptually related because both are
components
• The specifications are different
Enterprise Enterprise
Bean Bean
• The specifications do not build on each other or
EJB Container rely on each other
Clients
EJB Server
9 10
Represents Process
Session Bean
Enterprise EJB Scenario • Implements javax.ejb.SessionBean interface
Existing
Enterprise • Session Bean models the business process
EJB Application
Middleware • It does not guarantee persistency.
Clients Web Server
Server
CICS Programs • Database handling is avoided by session bean
Browser EJB Container (a) Stateful Session Bean
Credit Card (b) Stateless Session Bean
Servlet Shopping
(c) Singleton Session Bean
Databases
Cart
Inventory
Application
SAP Modules
EJB Server
11 12
2
12/6/2019
13 14
15 16
17 18
3
12/6/2019
19 20
Represents Data
Entity Bean Life Cycle of Entity Bean
• Implements javax.ejb.EntityBean interface
• Accessed by multiple clients at a time i.e. sharable.
• Persistent and Serializable
• Entity beans follows O-R mapping, so that in all maximum
cases, entity bean synchronized with RDBMS and by this it
achieves persistency.
• Each instance of an entity bean is one row of data
• Each instance of an entity bean is uniquely identified by a
primary key
• The container loads and stores the entity beans in the D/B
• In entity bean we have finder() along with the create() method
in home interface.
• create() always create a new row in database.
• finder() finds from the existing rows
21 22
23 24
4
12/6/2019
• The EJB container is responsible for • The entity bean is responsible for its persistent behavior
persistence • EJB developer must implement database access
• The container provides tools that generate code – ejbCreate(…), ejbLoad(), ejbStore(), ejbRemove()
in the EJB class that maps methods in the bean • Not automated, developer manually creates mapping
through JDBC calls
to a result set
• Not as reusable
– Can map to a table, view, join or stored procedure in
a database – Hard-code database access within class
– Server provides automated mapping to convert • Advanced features like connection pooling and caching
relational data to bean instances are difficult to support because of reliance on hand
written code
• Advanced features like connection pooling and
caching are easily supported
• High reuse
25 26
BMP offers a tactical approach CMP offers a more strategic Represents a specific client Represents underlying data
approach (1 instance per client) object or context
need a less sophisticated need a more sophisticated (clients share instance)
application server application server Short-lived Long-lived
developer handles everything vendor takes care of everything Transient Persistent
a BMP developer will have the For a CMP bean developer, there Can be any Java class Can be a class that maps to
responsibility of the is no need to worry about JDBC
persistent data
transactions and all databases. code and transactions, as all
databases are automatically
(e.g., database)
handled by the container May be transactional Always transactional
Business Logic Beans Beans which represent data
27 28
29 30
5
12/6/2019
31