SlideShare a Scribd company logo
1 of 53
Vibrant Technology 1
Enterprise Java Beans (EJB)
Vibrant Technology 2
EJB Goals
• Standard component architecture for building distributed
business applications in Java
• Interoperability between enterprise beans and other Java
Platform Enterprise Edition components, as well as non-
Java applications
• Compatible with other Java APIs and with CORBA
protocols
• Follow the Write Once, Run Anywhere philosophy of
Java - an enterprise bean can be developed once and
then deployed on multiple platforms without
recompilation or source code modification
• Define the “contracts” that enable tools from multiple
vendors to develop and deploy components that can
interoperate at runtime
Vibrant Technology 3
Reprise: 3-tiered architecture
Client
Database
Component middleware
Application logic components
Back-end tier
Middle tier
Front-end tier
LDAPDatabase
Client
Database
Component middleware
Application logic components
Back-end tier
Middle tier
Front-end tier
LDAPDatabase
Vibrant Technology 4
EJB 3-tiered architecture
Client
Database
Component middleware
Application logic components
Back-end tier
Middle tier
Front-end tier
LDAPDatabase
Application
server
EJBs
Vibrant Technology 5
Java EE 3-Tier Architecture
Vibrant Technology 6
EJBs as Components
• Enterprise Java Beans are components that
provide middle-tier business logic
• And interact heavily with the data layer of the
application
• EJB framework conforms to and at the same
time induces a 3-tier architecture for
distributed applications
Vibrant Technology 7
EJB as Component Model Framework
• Programming model
• Standardized interfaces
• Runtime environment
• Built-in component services (persistence,
transactions, security, etc.)
• Meta-data
• Deployment facilities
Vibrant Technology 8
EJB Specification
• EJB is an open specification - any vendor can develop a
runtime environment that complies with the specification
• EJB code intended to be portable across brands (assuming
uses only services defined by the spec, not additional vendor
facilities)
• EJB specs have evolved:
– Originated with IBM 1997
– Later adopted by Sun (1.0 1998, 1.1 1999)
– Enhanced under Java community process (2.0 2001, 2.1
2003, 3.0 2006)
• EJB 3.0 is a major departure from earlier versions, but
backwards compatible (old code works with 3.0 but not vice
versa)
Vibrant Technology 9
Enterprise Beans
• Body of code with fields and methods
• Encapsulates business data or business logic
that operates on the enterprise’s data
• Instances are created and managed at
runtime by a Container (application server)
• Client access is mediated by the bean
instance’s Container - isolates the bean from
direct access by client applications (and other
beans)
Vibrant Technology 10
Enterprise Bean Portability
• If an enterprise bean uses only the services defined by the
EJB specification (and not additional facilities peculiar to the
vendor), the bean can be deployed in any compliant EJB
Container
• Can be included in an assembled application without requiring
source code changes or recompilation
• Component services information, such as a transaction and
security attributes, are separate from the enterprise bean
class - this allows the services information to be managed by
tools during application assembly and deployment
• Can be customized at deployment time by editing the bean’s
environment entries and/or deployment descriptor
Vibrant Technology 11
EJB Container
• Manages every aspect of an enterprise bean
at runtime and implements component
services
• When a client application invokes a method
on an enterprise bean, the container first
intercepts the invocation to ensure
persistence, transactions and access control
are applied properly to every operation a client
performs on the bean
• An enterprise bean cannot function outside of
an EJB container
Vibrant Technology 12
EJB Container
Vibrant Technology 13
Resource Management
• Containers manage many beans simultaneously
• To reduce memory consumption and processing,
containers pool resources
• When a bean is not being used, a container may place it
in a pool to be reused by another client
• Or evict it from memory (passivate) and only bring it back
(activate) when its needed
• While its reference on the client remains intact
• When the client invokes a method on the reference, the
container re-incarnates the bean to service the request
Vibrant Technology 14
Business Data and Methods
• An entity bean (aka persistence entity) represents
persistent business data stored in one row of a
database table, and may add behavior specific to
that data - but the methods are often just getters,
setters and finders
• Session beans implement business processes and
interact with clients
• Message-driven beans combine features of a
session bean and a message listener, allowing a
business component to receive messages (and
event notifications) asynchronously
Vibrant Technology 15
Business Interfaces
• A “business interface” is required for both
session and message-driven beans (and for
entities prior to EJB 3.0)
• The business interface of a message-driven
bean is defined by the messaging type used
(typically MessageListener), not by the
developer
Vibrant Technology 16
Multiple Interfaces
• If a bean class implements only a single interface (not counting standard
interfaces such as java.io.Serializable or any of the javax.ejb interfaces), it
is deemed the “business interface” and is by default a local interface
unless designated by a @Remote annotation
• A bean class may have multiple interfaces, but one or more must be
designated as a business interface by either a @Local or @Remote
annotation
• Remote business interfaces support remote clients running on a different
JVM or machine, to which the bean’s location is transparent
• If there are only local interfaces, all clients must run in the same JVM as
the bean, and the location of the bean is not transparent
Vibrant Technology 17
Example
@Stateless @Remote
public class CalculatorBean implements Calculator {
public float add (int a, int b) {
return a + b;
}
public float subtract (int a, int b) {
return a - b;
}
}
public interface Calculator {
public float add (int a, int b);
public float subtract (int a, int b);
}
Vibrant Technology 18
Remote and Local Interfaces
• To allow remote access, must decorate the business interface with the
@Remote annotation
@Remote public interface InterfaceName { ... }
• OR decorate the bean class with @Remote, specifying the business
interface(s)
@Remote(InterfaceName.class) public class BeanName implements
InterfaceName { ... }
• To build an enterprise bean that allows only local access, optionally
annotate the business interface of the enterprise bean as @Local
@Local public interface InterfaceName { ... }
• OR specify the interface by decorating the bean class with @Local and
specify the interface name
@Local(InterfaceName.class) public class BeanName implements
InterfaceName { ... }
Vibrant Technology 19
Enterprise Beans as
Distributed Objects
• Business interfaces are types of Java RMI Remote
interfaces
• The java.rmi.Remote interface is used by
distributed objects to represent the bean in a
different address space (process or machine)
• An enterprise bean class is instantiated and lives in
its container but can be accessed by client
applications that live in other address spaces, using
skeletons and stubs implemented by the container
Vibrant Technology 20
Stubs and Skeletons
Vibrant Technology 21
Deciding on Local vs. Remote:
Coupling
• Tightly coupled beans depend on one another
• For example, if a session bean that processes
sales orders calls a session bean that emails
a confirmation message to the customer,
these beans are tightly coupled
• Tightly coupled beans are good candidates for
local access
• Because they fit together as a logical unit,
they typically call each other often and would
benefit from the increased performance that is
possible with local access
Vibrant Technology 22
Deciding on Local vs. Remote:
Type of Client
• If an enterprise bean is accessed by
application clients, then it should allow remote
access
• In a production environment, these clients
almost always run on different machines than
the Application Server
• If an enterprise bean’s clients are web
components or other enterprise beans, then
the type of access depends on how you want
to distribute your components
Vibrant Technology 23
Deciding on Local vs. Remote:
Component Distribution
• Java EE applications are scalable because
their server-side components can be
distributed across multiple machines
• In a distributed application, the web
components may run on a different server
than do the enterprise beans they access
• Then the enterprise beans should allow
remote access
Vibrant Technology 24
Deciding on Local vs. Remote:
Performance
• Due to factors such as network latency,
remote calls are often slower than local calls
• On the other hand, if you distribute
components among different servers, you may
improve the application’s overall performance
• Actual performance can vary in different
operational environments
Vibrant Technology 25
Deciding on Local vs. Remote
• If you aren’t sure which type of access an enterprise
bean should have, choose remote access, which
gives more flexibility
• In the future you can distribute your components to
accommodate the growing demands on your
application
• It is possible for an enterprise bean to allow both
remote and local access through different interfaces
(the same business interface cannot be both a local
and remote business interface)
Vibrant Technology 26
Session Beans
Vibrant Technology 27
Session Bean
• Represents a single client (at a time) inside
the Application Server
• Client invokes the session bean’s methods to
execute business tasks
• When the client terminates, the session bean
appears to have terminated and is no longer
associated with the client
Vibrant Technology 28
Stateful vs. Stateless
• There are two basic kinds of session bean: Stateless
and Stateful
• Stateful session beans encapsulate business logic
and state specific to a client
• Stateful beans are called "stateful" because they
maintain conversational state between method
invocations
• The state is held in instance variables (in memory)
and is not persistent across executions
• The state disappears when the client removes the
bean or terminates
Vibrant Technology 29
Stateful Session Beans
• To conserve resources, stateful session beans may be
passivated when not in use by the client
• Passivation means the bean's conversational-state is written
to secondary storage (disk) and the instance is removed from
memory
• If the client removes the bean or terminates, the session ends
and the state disappears
• The client's reference to the bean is not affected by
passivation: it remains alive and usable while the bean is
passivated
• When the client invokes a method on a bean that is
passivated, the container will activate the bean by
instantiating a new instance and populating its conversational-
state with the state previously written to secondary storage
Vibrant Technology 30
Stateless vs. Stateful
• Stateless session beans are made up of business
methods that behave like functions: they operate
only on the arguments passed to them when they
are invoked (but can lookup state in a database or
file)
• Stateless beans are called "stateless" because they
are transient - they do not maintain a conversational
state between method invocations
• The bean’s instance variables may contain a state
specific to the client during a single method
invocation, but not retained when the method is
finished
Vibrant Technology 31
Stateless Session Beans
• Each invocation of a stateless business
method is independent from previous
invocations
• Because stateless session beans are
"stateless" they tend to process requests
faster and use less resources
• All instances are equivalent – the EJB
container can assign a pooled stateless bean
instance to any client, improving scalability
Vibrant Technology 32
Session Bean Interfaces
• A client can access a session bean only through the
methods in the bean’s business interface
• Can have more than one business interface
• A business interface can be either local or remote (or
web service)
• Not required to implement any lifecycle methods, but
may optionally do so and annotate as such (prior to
EJB 3.0, all enterprise beans had to implement a
“home” interface with lifecycle methods)
Vibrant Technology 33
Lifecycle Methods
• The actual methods can have any names
• @PostConstruct: The container immediately calls the
annotated method after a bean instance is instantiated
• @Init: Designates initialization methods for a stateful
session bean
• @PrePassivate: Called before the container passivates a
stateful bean instance
• @PostActivate: Called when a re-activated stateful bean
instance is ready
• @Remove: Informs the container to remove the bean instance
from the object pool after the method executes (not actually a
callback)
• @PreDestroy: Called before the container destroys an
unused or expired bean instance from its object pool
Vibrant Technology 34
Lifecycle of a
Stateful Session Bean
• Client initiates the lifecycle by obtaining a reference
• Container invokes the @PostConstruct and @Init
methods, if any
• Now bean ready for client to invoke business methods
Vibrant Technology 35
Lifecycle of a
Stateful Session Bean
• While in ready state, container may passivate and invoke the
@PrePassivate method, if any
• If a client then invokes a business method, the container
invokes the @PostActivate method, if any, and it returns to
ready stage
Vibrant Technology 36
Lifecycle of a
Stateful Session Bean
• At the end of the life cycle, the client invokes a method
annotated @Remove
• The container calls the @PreDestroy method, if any
Vibrant Technology 37
Lifecycle of a
Stateless Session Bean
• A client initiates the life cycle by obtaining a reference
• The container invokes the @PostConstruct method, if any
• The bean is now ready to have its business methods invoked
by clients
Vibrant Technology 38
Lifecycle of a
Stateless Session Bean
• Because a stateless session bean is never passivated, its life
cycle has only two stages: nonexistent and ready for the
invocation of business methods.
• At the end of the life cycle, the container calls the
@PreDestroy method, if any
Vibrant Technology 39
Entity Beans
Vibrant Technology 40
Entity Beans
• Called entity beans < EJB 3.0, persistence entities
(or just entities) >= EJB 3.0
• Provides an object view of data in the database
– An entity class represents a table in a relational database
– An entity instance represents a row in that table
• Uses the Java Persistence API
• Annotated with @Entity
Vibrant Technology 41
Entity Beans
• An entity bean provides an object view of data in the
database
• Allows shared access from multiple users
• Can be long-lived (as long as data in the database)
• Persistent
– The entity and its remote reference survive a crash of the EJB
Container
– If the state of an entity was being updated by a transaction at the
time the container crashed, the entity’s state is automatically reset
to the state of the last committed transaction
– An application program can create an entity bean, then be
stopped and restarted, and again find the entity bean it was
working with - and continue using the same entity bean
Vibrant Technology 42
Instance Variables
• Persistent instance variables can only be
accessed through the entity class’ methods
• Must only be serializable types (so they can
be stored in a database)
• Object/relational mapping must be defined
• An entity may include non-persistent instance
variables, annotated as @Transient
Vibrant Technology 43
Entity Beans are Identified by a
Primary Key
• Entity Beans must have a primary key that uniquely
identifies it
• Used to locate the bean’s data in some underlying
database
• For example, an “employee” entity bean may have a
Social Security number as primary key
• You can only use entity beans when your objects
have a unique identifier field, or when you can add
such a field (or set of fields)
Vibrant Technology 44
Primary Keys
• May be either simple or composite
• Simple primary keys annotated @Id
• Composite primary keys defined by a primary key
class, annotated @IdClass
• The simple primary key, or each field of a composite
primary key, must be a Java primitive type, string or
date
• EntityManager.find method used to look up
entities by primary key, returns reference to the one
specific entity bean (exception if not found)
Vibrant Technology 45
Queries
• Other finder methods defined using SQL-like queries
in Java Persistence Query Language, return a
collection of entities that match the request
• EntityManager.createQuery method used to
create dynamic queries defined within business logic
public List findWithName(String name) {
return em.createQuery(
"SELECT c FROM Customer c WHERE c.name
LIKE :custName")
.setParameter("custName", name)
.setMaxResults(10)
.getResultList();
}
Vibrant Technology 46
Queries
• EntityManager.createNamedQuery method used to
create static queries defined in annotation metadata
@NamedQuery(
name="findAllCustomersWithName",
query="SELECT c FROM Customer c WHERE c.name
LIKE :custName"
)
customers =
em.createNamedQuery("findAllCustomersWithName")
.setParameter("custName", "Smith")
.getResultList();
Vibrant Technology 47
Managing Entities
• An Entity Manager is associated with a persistence
context corresponding to a particular data store
• State of persistent entities automatically
synchronized to the database when the associated
transaction commits
• But business logic for transactions resides in session
or message-driven beans
• Both Container-Managed Entity Managers
(automatic) and Application-Managed Entity
Managers
Vibrant Technology 48
Container-Managed Transactions
• Container sets the boundaries of transactions,
cannot use operations like commit or rollback
within code
• Container begins transaction immediately before
enterprise bean method starts and commits just
before method exits
• Transaction types: Required, RequiresNew,
Mandatory, NotSupported, Supports,
Never
Vibrant Technology 49
Transactional Attributes
• Required - If the client is running within a transaction and invokes the enterprise bean's
method, the method executes within the client's transaction. If the client is not associated
with a transaction, the container starts a new transaction before running the method.
• RequiresNew - If the client is running within a transaction and invokes the enterprise bean's
method, the container suspends the client's transaction, starts a new transaction, delegates
the call to the method, resumes the client's transaction after the method completes; if the
client is not associated with a transaction, the container starts a new transaction before
running the method.
• NotSupported - If the client is running within a transaction and invokes the enterprise bean's
method, the container suspends the client's transaction before invoking the method; after the
method has completed, the container resumes the client's transaction.
• Supports - If the client is running within a transaction and invokes the enterprise bean's
method, the method executes within the client's transaction; if the client is not associated with
a transaction, the container does not start a new transaction before running the method
• Mandatory - If the client is running within a transaction and invokes the enterprise bean's
method, the method executes within the client's transaction; if the client is not associated with
a transaction, the container throws the TransactionRequiredException.
• Never - If the client is running within a transaction and invokes the enterprise bean's method,
the container throws a RemoteException
Vibrant Technology 50
Application-Managed Transactions
• The code in the session or message-driven bean explicitly
marks the boundaries of the transaction
• Useful for implementing multiple transactions within a single
method or transactions than span multiple methods
• Can use either Java Database Connectivity (JDBC) or the
Java Transaction API (JTA)
• A JTA transaction can span updates to multiple databases
from different vendors managed by the Java Transaction
Service, but cannot support nested transactions
• JTA supplies begin, commit and rollback methods
Vibrant Technology 51
Using Transactions in
Session Beans
• A stateless session bean with bean-managed
transactions must commit or rollback before
returning
• A stateful session bean using JTA transactions
retains its association with a transaction across
multiple client calls, even if the database connection
is opened and closed
• A stateful session bean using JDBC transactions
loses its transaction association if the connection is
closed
Vibrant Technology 52
Saving a Session Bean’s State in a
Database
• Transactions normally concerned with synchronizing
the state of persistent entities to databases
• Optional for a stateful session bean to receive
transaction synchronization notifications to also store
its own data in a database
• Then must implement the
SessionSynchronization interface, supplying
afterBegin, beforeCompletion and
afterCompletion methods
Thank You…
Vibrant Technology 53

More Related Content

What's hot

Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecturetayab4687
 
Pilot Study - WSO2 Enterprise Integrator v6.1.1
Pilot Study - WSO2 Enterprise Integrator v6.1.1Pilot Study - WSO2 Enterprise Integrator v6.1.1
Pilot Study - WSO2 Enterprise Integrator v6.1.1GaneshNagalingam1
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in javaAcp Jamod
 
Integrating WebSphere Service Registry and Repository V8 with Process Server
Integrating WebSphere Service Registry and Repository V8 with Process ServerIntegrating WebSphere Service Registry and Repository V8 with Process Server
Integrating WebSphere Service Registry and Repository V8 with Process ServerGaneshNagalingam1
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)Fahad Golra
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Armen Arzumanyan
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfoliocummings49
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejbNiraj Bharambe
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJBPeter R. Egli
 
Java unit 4_cs_notes
Java unit 4_cs_notesJava unit 4_cs_notes
Java unit 4_cs_notesNiraj Bharambe
 
Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...mfrancis
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJBodedns
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanStephan Janssen
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
Mcv design patterns
Mcv design patternsMcv design patterns
Mcv design patternsRob Paok
 

What's hot (20)

Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Pilot Study - WSO2 Enterprise Integrator v6.1.1
Pilot Study - WSO2 Enterprise Integrator v6.1.1Pilot Study - WSO2 Enterprise Integrator v6.1.1
Pilot Study - WSO2 Enterprise Integrator v6.1.1
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Integrating WebSphere Service Registry and Repository V8 with Process Server
Integrating WebSphere Service Registry and Repository V8 with Process ServerIntegrating WebSphere Service Registry and Repository V8 with Process Server
Integrating WebSphere Service Registry and Repository V8 with Process Server
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
Java bean
Java beanJava bean
Java bean
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
Java unit 4_cs_notes
Java unit 4_cs_notesJava unit 4_cs_notes
Java unit 4_cs_notes
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
EJB 2
EJB 2EJB 2
EJB 2
 
Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...Common Security Services. Consolidation patterns for legacy components - Stef...
Common Security Services. Consolidation patterns for legacy components - Stef...
 
JEE Course - EJB
JEE Course - EJBJEE Course - EJB
JEE Course - EJB
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Mcv design patterns
Mcv design patternsMcv design patterns
Mcv design patterns
 

Viewers also liked

Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbaivibrantuser
 
Galaxy design sample Ó€ Worker Ant
Galaxy design sample Ó€ Worker AntGalaxy design sample Ó€ Worker Ant
Galaxy design sample Ó€ Worker AntWorker Ant
 
Planning Optimal Lotus Quickr services for Portal (J2EE) Deployments
Planning Optimal Lotus Quickr services for Portal (J2EE) DeploymentsPlanning Optimal Lotus Quickr services for Portal (J2EE) Deployments
Planning Optimal Lotus Quickr services for Portal (J2EE) DeploymentsStuart McIntyre
 
Presentation design sample Ó€ Worker Ant
Presentation design sample Ó€ Worker AntPresentation design sample Ó€ Worker Ant
Presentation design sample Ó€ Worker AntWorker Ant
 
JUnit Goodness
JUnit GoodnessJUnit Goodness
JUnit GoodnessPeter Sellars
 
Munit junit test case
Munit junit test caseMunit junit test case
Munit junit test caseprudhvivreddy
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorialjbarciauskas
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2vikram singh
 
GeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by testsGeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by testsJakub Marchwicki
 
Testdriven Development using JUnit and EasyMock
Testdriven Development using JUnit and EasyMockTestdriven Development using JUnit and EasyMock
Testdriven Development using JUnit and EasyMockschlebu
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
Integrating GWT, Spring and Hibernate ORM
Integrating GWT, Spring and Hibernate ORMIntegrating GWT, Spring and Hibernate ORM
Integrating GWT, Spring and Hibernate ORMMarakana Inc.
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
J2EE Performance And Scalability Bp
J2EE Performance And Scalability BpJ2EE Performance And Scalability Bp
J2EE Performance And Scalability BpChris Adkin
 
Learn About Continuous Integration With Hudson Directly From the Source
Learn About Continuous Integration With Hudson Directly From the SourceLearn About Continuous Integration With Hudson Directly From the Source
Learn About Continuous Integration With Hudson Directly From the SourceMarakana Inc.
 

Viewers also liked (20)

Hibernate reference
Hibernate referenceHibernate reference
Hibernate reference
 
Ejb course in-mumbai
Ejb course in-mumbaiEjb course in-mumbai
Ejb course in-mumbai
 
Galaxy design sample Ó€ Worker Ant
Galaxy design sample Ó€ Worker AntGalaxy design sample Ó€ Worker Ant
Galaxy design sample Ó€ Worker Ant
 
Planning Optimal Lotus Quickr services for Portal (J2EE) Deployments
Planning Optimal Lotus Quickr services for Portal (J2EE) DeploymentsPlanning Optimal Lotus Quickr services for Portal (J2EE) Deployments
Planning Optimal Lotus Quickr services for Portal (J2EE) Deployments
 
Presentation design sample Ó€ Worker Ant
Presentation design sample Ó€ Worker AntPresentation design sample Ó€ Worker Ant
Presentation design sample Ó€ Worker Ant
 
JUnit Goodness
JUnit GoodnessJUnit Goodness
JUnit Goodness
 
Munit junit test case
Munit junit test caseMunit junit test case
Munit junit test case
 
Oop l3n
Oop l3nOop l3n
Oop l3n
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorial
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Maven
MavenMaven
Maven
 
Java & J2EE Coding Conventions
Java & J2EE Coding ConventionsJava & J2EE Coding Conventions
Java & J2EE Coding Conventions
 
GeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by testsGeeCON 2013 - EJB application guided by tests
GeeCON 2013 - EJB application guided by tests
 
Testdriven Development using JUnit and EasyMock
Testdriven Development using JUnit and EasyMockTestdriven Development using JUnit and EasyMock
Testdriven Development using JUnit and EasyMock
 
JMS 2.0
JMS 2.0JMS 2.0
JMS 2.0
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Integrating GWT, Spring and Hibernate ORM
Integrating GWT, Spring and Hibernate ORMIntegrating GWT, Spring and Hibernate ORM
Integrating GWT, Spring and Hibernate ORM
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
J2EE Performance And Scalability Bp
J2EE Performance And Scalability BpJ2EE Performance And Scalability Bp
J2EE Performance And Scalability Bp
 
Learn About Continuous Integration With Hudson Directly From the Source
Learn About Continuous Integration With Hudson Directly From the SourceLearn About Continuous Integration With Hudson Directly From the Source
Learn About Continuous Integration With Hudson Directly From the Source
 

Similar to Ejb course-in-mumbai

Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2sandeep54552
 
enterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfenterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfEidTahir
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEEFahad Golra
 
J2 ee container & components
J2 ee container & componentsJ2 ee container & components
J2 ee container & componentsKeshab Nath
 
Transforming to Microservices
Transforming to MicroservicesTransforming to Microservices
Transforming to MicroservicesKyle Brown
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.pptKrishna900061
 
Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352sflynn073
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansPawanMM
 
Middle ware Technologies
Middle ware TechnologiesMiddle ware Technologies
Middle ware Technologiesprakashk453625
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologiesprakashk453625
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)Kevin Sutter
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlArjun Thakur
 
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesChapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesIt Academy
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Hitesh-Java
 

Similar to Ejb course-in-mumbai (20)

UNIT 4.pptx
UNIT 4.pptxUNIT 4.pptx
UNIT 4.pptx
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
 
enterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfenterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdf
 
4. J2EE.pptx
4. J2EE.pptx4. J2EE.pptx
4. J2EE.pptx
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
 
J2 ee container & components
J2 ee container & componentsJ2 ee container & components
J2 ee container & components
 
Transforming to Microservices
Transforming to MicroservicesTransforming to Microservices
Transforming to Microservices
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
Hybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbaiHybernat and structs, spring classes in mumbai
Hybernat and structs, spring classes in mumbai
 
Ra framework 0.1
Ra framework 0.1Ra framework 0.1
Ra framework 0.1
 
Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352Was l iberty for java batch and jsr352
Was l iberty for java batch and jsr352
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
Middle ware Technologies
Middle ware TechnologiesMiddle ware Technologies
Middle ware Technologies
 
.net Based Component Technologies
.net Based Component Technologies.net Based Component Technologies
.net Based Component Technologies
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesChapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration Technologies
 
Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans Spring - Part 1 - IoC, Di and Beans
Spring - Part 1 - IoC, Di and Beans
 

Recently uploaded

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Ejb course-in-mumbai

  • 2. Vibrant Technology 2 EJB Goals • Standard component architecture for building distributed business applications in Java • Interoperability between enterprise beans and other Java Platform Enterprise Edition components, as well as non- Java applications • Compatible with other Java APIs and with CORBA protocols • Follow the Write Once, Run Anywhere philosophy of Java - an enterprise bean can be developed once and then deployed on multiple platforms without recompilation or source code modification • Define the “contracts” that enable tools from multiple vendors to develop and deploy components that can interoperate at runtime
  • 3. Vibrant Technology 3 Reprise: 3-tiered architecture Client Database Component middleware Application logic components Back-end tier Middle tier Front-end tier LDAPDatabase Client Database Component middleware Application logic components Back-end tier Middle tier Front-end tier LDAPDatabase
  • 4. Vibrant Technology 4 EJB 3-tiered architecture Client Database Component middleware Application logic components Back-end tier Middle tier Front-end tier LDAPDatabase Application server EJBs
  • 5. Vibrant Technology 5 Java EE 3-Tier Architecture
  • 6. Vibrant Technology 6 EJBs as Components • Enterprise Java Beans are components that provide middle-tier business logic • And interact heavily with the data layer of the application • EJB framework conforms to and at the same time induces a 3-tier architecture for distributed applications
  • 7. Vibrant Technology 7 EJB as Component Model Framework • Programming model • Standardized interfaces • Runtime environment • Built-in component services (persistence, transactions, security, etc.) • Meta-data • Deployment facilities
  • 8. Vibrant Technology 8 EJB Specification • EJB is an open specification - any vendor can develop a runtime environment that complies with the specification • EJB code intended to be portable across brands (assuming uses only services defined by the spec, not additional vendor facilities) • EJB specs have evolved: – Originated with IBM 1997 – Later adopted by Sun (1.0 1998, 1.1 1999) – Enhanced under Java community process (2.0 2001, 2.1 2003, 3.0 2006) • EJB 3.0 is a major departure from earlier versions, but backwards compatible (old code works with 3.0 but not vice versa)
  • 9. Vibrant Technology 9 Enterprise Beans • Body of code with fields and methods • Encapsulates business data or business logic that operates on the enterprise’s data • Instances are created and managed at runtime by a Container (application server) • Client access is mediated by the bean instance’s Container - isolates the bean from direct access by client applications (and other beans)
  • 10. Vibrant Technology 10 Enterprise Bean Portability • If an enterprise bean uses only the services defined by the EJB specification (and not additional facilities peculiar to the vendor), the bean can be deployed in any compliant EJB Container • Can be included in an assembled application without requiring source code changes or recompilation • Component services information, such as a transaction and security attributes, are separate from the enterprise bean class - this allows the services information to be managed by tools during application assembly and deployment • Can be customized at deployment time by editing the bean’s environment entries and/or deployment descriptor
  • 11. Vibrant Technology 11 EJB Container • Manages every aspect of an enterprise bean at runtime and implements component services • When a client application invokes a method on an enterprise bean, the container first intercepts the invocation to ensure persistence, transactions and access control are applied properly to every operation a client performs on the bean • An enterprise bean cannot function outside of an EJB container
  • 13. Vibrant Technology 13 Resource Management • Containers manage many beans simultaneously • To reduce memory consumption and processing, containers pool resources • When a bean is not being used, a container may place it in a pool to be reused by another client • Or evict it from memory (passivate) and only bring it back (activate) when its needed • While its reference on the client remains intact • When the client invokes a method on the reference, the container re-incarnates the bean to service the request
  • 14. Vibrant Technology 14 Business Data and Methods • An entity bean (aka persistence entity) represents persistent business data stored in one row of a database table, and may add behavior specific to that data - but the methods are often just getters, setters and finders • Session beans implement business processes and interact with clients • Message-driven beans combine features of a session bean and a message listener, allowing a business component to receive messages (and event notifications) asynchronously
  • 15. Vibrant Technology 15 Business Interfaces • A “business interface” is required for both session and message-driven beans (and for entities prior to EJB 3.0) • The business interface of a message-driven bean is defined by the messaging type used (typically MessageListener), not by the developer
  • 16. Vibrant Technology 16 Multiple Interfaces • If a bean class implements only a single interface (not counting standard interfaces such as java.io.Serializable or any of the javax.ejb interfaces), it is deemed the “business interface” and is by default a local interface unless designated by a @Remote annotation • A bean class may have multiple interfaces, but one or more must be designated as a business interface by either a @Local or @Remote annotation • Remote business interfaces support remote clients running on a different JVM or machine, to which the bean’s location is transparent • If there are only local interfaces, all clients must run in the same JVM as the bean, and the location of the bean is not transparent
  • 17. Vibrant Technology 17 Example @Stateless @Remote public class CalculatorBean implements Calculator { public float add (int a, int b) { return a + b; } public float subtract (int a, int b) { return a - b; } } public interface Calculator { public float add (int a, int b); public float subtract (int a, int b); }
  • 18. Vibrant Technology 18 Remote and Local Interfaces • To allow remote access, must decorate the business interface with the @Remote annotation @Remote public interface InterfaceName { ... } • OR decorate the bean class with @Remote, specifying the business interface(s) @Remote(InterfaceName.class) public class BeanName implements InterfaceName { ... } • To build an enterprise bean that allows only local access, optionally annotate the business interface of the enterprise bean as @Local @Local public interface InterfaceName { ... } • OR specify the interface by decorating the bean class with @Local and specify the interface name @Local(InterfaceName.class) public class BeanName implements InterfaceName { ... }
  • 19. Vibrant Technology 19 Enterprise Beans as Distributed Objects • Business interfaces are types of Java RMI Remote interfaces • The java.rmi.Remote interface is used by distributed objects to represent the bean in a different address space (process or machine) • An enterprise bean class is instantiated and lives in its container but can be accessed by client applications that live in other address spaces, using skeletons and stubs implemented by the container
  • 21. Vibrant Technology 21 Deciding on Local vs. Remote: Coupling • Tightly coupled beans depend on one another • For example, if a session bean that processes sales orders calls a session bean that emails a confirmation message to the customer, these beans are tightly coupled • Tightly coupled beans are good candidates for local access • Because they fit together as a logical unit, they typically call each other often and would benefit from the increased performance that is possible with local access
  • 22. Vibrant Technology 22 Deciding on Local vs. Remote: Type of Client • If an enterprise bean is accessed by application clients, then it should allow remote access • In a production environment, these clients almost always run on different machines than the Application Server • If an enterprise bean’s clients are web components or other enterprise beans, then the type of access depends on how you want to distribute your components
  • 23. Vibrant Technology 23 Deciding on Local vs. Remote: Component Distribution • Java EE applications are scalable because their server-side components can be distributed across multiple machines • In a distributed application, the web components may run on a different server than do the enterprise beans they access • Then the enterprise beans should allow remote access
  • 24. Vibrant Technology 24 Deciding on Local vs. Remote: Performance • Due to factors such as network latency, remote calls are often slower than local calls • On the other hand, if you distribute components among different servers, you may improve the application’s overall performance • Actual performance can vary in different operational environments
  • 25. Vibrant Technology 25 Deciding on Local vs. Remote • If you aren’t sure which type of access an enterprise bean should have, choose remote access, which gives more flexibility • In the future you can distribute your components to accommodate the growing demands on your application • It is possible for an enterprise bean to allow both remote and local access through different interfaces (the same business interface cannot be both a local and remote business interface)
  • 27. Vibrant Technology 27 Session Bean • Represents a single client (at a time) inside the Application Server • Client invokes the session bean’s methods to execute business tasks • When the client terminates, the session bean appears to have terminated and is no longer associated with the client
  • 28. Vibrant Technology 28 Stateful vs. Stateless • There are two basic kinds of session bean: Stateless and Stateful • Stateful session beans encapsulate business logic and state specific to a client • Stateful beans are called "stateful" because they maintain conversational state between method invocations • The state is held in instance variables (in memory) and is not persistent across executions • The state disappears when the client removes the bean or terminates
  • 29. Vibrant Technology 29 Stateful Session Beans • To conserve resources, stateful session beans may be passivated when not in use by the client • Passivation means the bean's conversational-state is written to secondary storage (disk) and the instance is removed from memory • If the client removes the bean or terminates, the session ends and the state disappears • The client's reference to the bean is not affected by passivation: it remains alive and usable while the bean is passivated • When the client invokes a method on a bean that is passivated, the container will activate the bean by instantiating a new instance and populating its conversational- state with the state previously written to secondary storage
  • 30. Vibrant Technology 30 Stateless vs. Stateful • Stateless session beans are made up of business methods that behave like functions: they operate only on the arguments passed to them when they are invoked (but can lookup state in a database or file) • Stateless beans are called "stateless" because they are transient - they do not maintain a conversational state between method invocations • The bean’s instance variables may contain a state specific to the client during a single method invocation, but not retained when the method is finished
  • 31. Vibrant Technology 31 Stateless Session Beans • Each invocation of a stateless business method is independent from previous invocations • Because stateless session beans are "stateless" they tend to process requests faster and use less resources • All instances are equivalent – the EJB container can assign a pooled stateless bean instance to any client, improving scalability
  • 32. Vibrant Technology 32 Session Bean Interfaces • A client can access a session bean only through the methods in the bean’s business interface • Can have more than one business interface • A business interface can be either local or remote (or web service) • Not required to implement any lifecycle methods, but may optionally do so and annotate as such (prior to EJB 3.0, all enterprise beans had to implement a “home” interface with lifecycle methods)
  • 33. Vibrant Technology 33 Lifecycle Methods • The actual methods can have any names • @PostConstruct: The container immediately calls the annotated method after a bean instance is instantiated • @Init: Designates initialization methods for a stateful session bean • @PrePassivate: Called before the container passivates a stateful bean instance • @PostActivate: Called when a re-activated stateful bean instance is ready • @Remove: Informs the container to remove the bean instance from the object pool after the method executes (not actually a callback) • @PreDestroy: Called before the container destroys an unused or expired bean instance from its object pool
  • 34. Vibrant Technology 34 Lifecycle of a Stateful Session Bean • Client initiates the lifecycle by obtaining a reference • Container invokes the @PostConstruct and @Init methods, if any • Now bean ready for client to invoke business methods
  • 35. Vibrant Technology 35 Lifecycle of a Stateful Session Bean • While in ready state, container may passivate and invoke the @PrePassivate method, if any • If a client then invokes a business method, the container invokes the @PostActivate method, if any, and it returns to ready stage
  • 36. Vibrant Technology 36 Lifecycle of a Stateful Session Bean • At the end of the life cycle, the client invokes a method annotated @Remove • The container calls the @PreDestroy method, if any
  • 37. Vibrant Technology 37 Lifecycle of a Stateless Session Bean • A client initiates the life cycle by obtaining a reference • The container invokes the @PostConstruct method, if any • The bean is now ready to have its business methods invoked by clients
  • 38. Vibrant Technology 38 Lifecycle of a Stateless Session Bean • Because a stateless session bean is never passivated, its life cycle has only two stages: nonexistent and ready for the invocation of business methods. • At the end of the life cycle, the container calls the @PreDestroy method, if any
  • 40. Vibrant Technology 40 Entity Beans • Called entity beans < EJB 3.0, persistence entities (or just entities) >= EJB 3.0 • Provides an object view of data in the database – An entity class represents a table in a relational database – An entity instance represents a row in that table • Uses the Java Persistence API • Annotated with @Entity
  • 41. Vibrant Technology 41 Entity Beans • An entity bean provides an object view of data in the database • Allows shared access from multiple users • Can be long-lived (as long as data in the database) • Persistent – The entity and its remote reference survive a crash of the EJB Container – If the state of an entity was being updated by a transaction at the time the container crashed, the entity’s state is automatically reset to the state of the last committed transaction – An application program can create an entity bean, then be stopped and restarted, and again find the entity bean it was working with - and continue using the same entity bean
  • 42. Vibrant Technology 42 Instance Variables • Persistent instance variables can only be accessed through the entity class’ methods • Must only be serializable types (so they can be stored in a database) • Object/relational mapping must be defined • An entity may include non-persistent instance variables, annotated as @Transient
  • 43. Vibrant Technology 43 Entity Beans are Identified by a Primary Key • Entity Beans must have a primary key that uniquely identifies it • Used to locate the bean’s data in some underlying database • For example, an “employee” entity bean may have a Social Security number as primary key • You can only use entity beans when your objects have a unique identifier field, or when you can add such a field (or set of fields)
  • 44. Vibrant Technology 44 Primary Keys • May be either simple or composite • Simple primary keys annotated @Id • Composite primary keys defined by a primary key class, annotated @IdClass • The simple primary key, or each field of a composite primary key, must be a Java primitive type, string or date • EntityManager.find method used to look up entities by primary key, returns reference to the one specific entity bean (exception if not found)
  • 45. Vibrant Technology 45 Queries • Other finder methods defined using SQL-like queries in Java Persistence Query Language, return a collection of entities that match the request • EntityManager.createQuery method used to create dynamic queries defined within business logic public List findWithName(String name) { return em.createQuery( "SELECT c FROM Customer c WHERE c.name LIKE :custName") .setParameter("custName", name) .setMaxResults(10) .getResultList(); }
  • 46. Vibrant Technology 46 Queries • EntityManager.createNamedQuery method used to create static queries defined in annotation metadata @NamedQuery( name="findAllCustomersWithName", query="SELECT c FROM Customer c WHERE c.name LIKE :custName" ) customers = em.createNamedQuery("findAllCustomersWithName") .setParameter("custName", "Smith") .getResultList();
  • 47. Vibrant Technology 47 Managing Entities • An Entity Manager is associated with a persistence context corresponding to a particular data store • State of persistent entities automatically synchronized to the database when the associated transaction commits • But business logic for transactions resides in session or message-driven beans • Both Container-Managed Entity Managers (automatic) and Application-Managed Entity Managers
  • 48. Vibrant Technology 48 Container-Managed Transactions • Container sets the boundaries of transactions, cannot use operations like commit or rollback within code • Container begins transaction immediately before enterprise bean method starts and commits just before method exits • Transaction types: Required, RequiresNew, Mandatory, NotSupported, Supports, Never
  • 49. Vibrant Technology 49 Transactional Attributes • Required - If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction. If the client is not associated with a transaction, the container starts a new transaction before running the method. • RequiresNew - If the client is running within a transaction and invokes the enterprise bean's method, the container suspends the client's transaction, starts a new transaction, delegates the call to the method, resumes the client's transaction after the method completes; if the client is not associated with a transaction, the container starts a new transaction before running the method. • NotSupported - If the client is running within a transaction and invokes the enterprise bean's method, the container suspends the client's transaction before invoking the method; after the method has completed, the container resumes the client's transaction. • Supports - If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction; if the client is not associated with a transaction, the container does not start a new transaction before running the method • Mandatory - If the client is running within a transaction and invokes the enterprise bean's method, the method executes within the client's transaction; if the client is not associated with a transaction, the container throws the TransactionRequiredException. • Never - If the client is running within a transaction and invokes the enterprise bean's method, the container throws a RemoteException
  • 50. Vibrant Technology 50 Application-Managed Transactions • The code in the session or message-driven bean explicitly marks the boundaries of the transaction • Useful for implementing multiple transactions within a single method or transactions than span multiple methods • Can use either Java Database Connectivity (JDBC) or the Java Transaction API (JTA) • A JTA transaction can span updates to multiple databases from different vendors managed by the Java Transaction Service, but cannot support nested transactions • JTA supplies begin, commit and rollback methods
  • 51. Vibrant Technology 51 Using Transactions in Session Beans • A stateless session bean with bean-managed transactions must commit or rollback before returning • A stateful session bean using JTA transactions retains its association with a transaction across multiple client calls, even if the database connection is opened and closed • A stateful session bean using JDBC transactions loses its transaction association if the connection is closed
  • 52. Vibrant Technology 52 Saving a Session Bean’s State in a Database • Transactions normally concerned with synchronizing the state of persistent entities to databases • Optional for a stateful session bean to receive transaction synchronization notifications to also store its own data in a database • Then must implement the SessionSynchronization interface, supplying afterBegin, beforeCompletion and afterCompletion methods