Java Reference
In-Depth Information
EJB 3.2 - an overview
Based on the Enterprise JavaBeans ( EJB ) specification, Enterprise JavaBeans are com-
ponents that typically implement the business logic of Java Enterprise Edition applications
(for Java EE, note that Oracle advises against using JEE as the acronym for Java Enterprise
Edition; for more information about acronyms for Java-related technologies, visit ht-
tps://java.net/projects/javaee-spec/pages/JEE ) . Because of their transactional nature, EJBs
are also commonly used for the construction of the data access layer in many applications.
However, in the newest version of the specification, container-managed transactions are no
longer exclusive for Enterprise JavaBeans and can be reused in other parts of the Java EE
platform.
There are basically three types of Enterprise JavaBeans:
Session beans : This is the most commonly used EJB type. The container manages
multiple instances of every class that is defined as a session bean (with an excep-
tion for singletons, which have only one instance). When an operation implemen-
ted by EJB must be executed (for example, because a user has requested an update
of an entity in the database), the container assigns a session bean instance for the
specific user. This code is then executed on behalf of the calling client. The con-
tainer is responsible for providing session beans with multiple system-level ser-
vices, for example, security, transactions, or distribution of beans.
Message-driven beans ( MDB ): MDBs are Enterprise beans that can asynchron-
ously process messages sent by any JMS producer. (We will discuss MDBs in
Chapter 6 , Developing Applications with JBoss JMS Provider .)
Entity objects : An EJB is used to represent entities in a database. The newest ver-
sion of the specification made this type of Enterprise JavaBeans optional, so they
may not be supported in all containers (their support has also been dropped in
WildFly). Entity objects will be removed from the specification in Java EE 8. Cur-
rently, in Java EE 7, the main persistence technology is Java Persistence API. We
will discuss JPA in Chapter 5 , Combining Persistence with CDI .
Additionally, session beans can be divided into three subtypes based on their characteristics
and usage scenarios.
Stateless session beans ( SLSB ): These are objects whose instances have no con-
versational state with the client that has invoked an operation on them. This means
that all these bean instances are equal when they are not servicing a client, and the
container can prepare a pool for them to handle multiple requests in parallel. Be-
Search WWH ::




Custom Search