Jakarta Enterprise Beans (EJB; formerly Enterprise JavaBeans) is one of several
Java API
There are two types of Java programming language application programming interfaces (APIs):
* The official core Java API, contained in the Android (Google), SE (OpenJDK and Oracle), MicroEJ. These packages (java.* packages) are the core Java la ...
s for modular construction of
enterprise software
Enterprise software, also known as enterprise application software (EAS), is computer software used to satisfy the needs of an organization rather than individual users. Such organizations include businesses, schools, interest-based user groups, ...
. EJB is a
server-side
In the client–server model, server-side refers to programs and operations that run on the server. This is in contrast to client-side programs and operations which run on the client.
General concepts
Typically, a server is a computer application ...
software component
Component-based software engineering (CBSE), also called component-based development (CBD), is a branch of software engineering that emphasizes the separation of concerns with respect to the wide-ranging functionality available throughout a give ...
that
encapsulates business logic In computer software, business logic or domain logic is the part of the program that encodes the real-world business rules that determine how data can be created, stored, and changed. It is contrasted with the remainder of the software that might ...
of an application. An EJB
web container
A web container (also known as a servlet container;
and compare "webcontainer"
) is the component of a web server that interacts with Jakarta Servlets. A web container is responsible for managing the lifecycle of servlets, mapping a URL to a par ...
provides a
runtime environment
In computer programming, a runtime system or runtime environment is a sub-system that exists both in the computer where a program is created, as well as in the computers where the program is intended to be run. The name comes from the compile t ...
for web related software components, including
computer security
Computer security, cybersecurity (cyber security), or information technology security (IT security) is the protection of computer systems and networks from attack by malicious actors that may result in unauthorized information disclosure, the ...
,
Java servlet lifecycle management,
transaction processing
Transaction processing is information processing in computer science that is divided into individual, indivisible operations called ''transactions''. Each transaction must succeed or fail as a complete unit; it can never be only partially comple ...
, and other
web services. The EJB specification is a subset of the
Java EE
Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web serv ...
specification.
Specification
The EJB specification was originally developed in 1997 by
IBM and later adopted by
Sun Microsystems
Sun Microsystems, Inc. (Sun for short) was an American technology company that sold computers, computer components, software, and information technology services and created the Java programming language, the Solaris operating system, ZFS, the ...
(EJB 1.0 and 1.1) in 1999 and enhanced under the
Java Community Process
The Java Community Process (JCP), established in 1998, is a formalized mechanism that allows interested parties to develop standard technical specifications for Java technology. Anyone can become a JCP Member by filling a form available at thJCP w ...
a
JSR 19(EJB 2.0)
JSR 153(EJB 2.1)
JSR 220(EJB 3.0)
JSR 318(EJB 3.1) an
JSR 345(EJB 3.2).
The EJB specification provides a standard way to implement the server-side (also called "
back-end") 'business' software typically found in enterprise applications (as opposed to 'front-end'
user interface
In the industrial design field of human–computer interaction, a user interface (UI) is the space where interactions between humans and machines occur. The goal of this interaction is to allow effective operation and control of the machine f ...
software). Such software addresses the same types of problem, and solutions to these problems are often repeatedly re-implemented by programmers. Jakarta Enterprise Beans is intended to handle such common concerns as
persistence,
transactional integrity and
security
Security is protection from, or resilience against, potential harm (or other unwanted coercive change) caused by others, by restraining the freedom of others to act. Beneficiaries (technically referents) of security may be of persons and social ...
in a standard way, leaving programmers free to concentrate on the particular parts of the enterprise software at hand.
General responsibilities
The EJB specification details how an
application server
An application server is a server that hosts applications or software that delivers a business application through a communication protocol.
An application server framework is a service layer model. It includes software components available to a ...
provides the following responsibilities:
*
Transaction processing
Transaction processing is information processing in computer science that is divided into individual, indivisible operations called ''transactions''. Each transaction must succeed or fail as a complete unit; it can never be only partially comple ...
* Integration with the
persistence services offered by the
Jakarta Persistence
Jakarta Persistence (JPA; formerly Java Persistence API) is a Jakarta EE application programming interface specification that describes the management of relational data in enterprise Java applications.
Persistence in this context covers three a ...
(JPA)
*
Concurrency control
In information technology and computer science, especially in the fields of computer programming, operating systems, multiprocessors, and databases, concurrency control ensures that correct results for Concurrent computing, concurrent operations a ...
*
Event-driven programming
In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions ( mouse clicks, key presses), sensor outputs, or message passing from other programs or t ...
using
Jakarta Messaging
The Jakarta Messaging API (formerly Java Message Service or JMS API) is a Java application programming interface (API) for message-oriented middleware. It provides generic messaging models, able to handle the producer–consumer problem, that can ...
(JMS) and
Jakarta Connectors
Jakarta Connectors (JCA; formerly Java EE Connector Architecture and J2EE Connector Architecture) is a Java programming language tool for connecting application servers and enterprise information systems (EIS) as part of enterprise application i ...
(JCA)
*
Asynchronous method invocation
In multithreaded computer programming, asynchronous method invocation (AMI), also known as asynchronous method calls or the asynchronous pattern is a design pattern in which the call site is not blocked while waiting for the called code to finish ...
*
Job scheduling
A job scheduler is a computer application for controlling unattended background program execution of jobs. This is commonly called batch scheduling, as execution of non-interactive jobs is often called batch processing, though traditional ''job'' ...
* Naming and
directory service
In computing, a directory service or name service maps the names of network resources to their respective network addresses. It is a shared information infrastructure for locating, managing, administering and organizing everyday items and network r ...
s via
Java Naming and Directory Interface
The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and resources (in the form of Java objects) via a name. Like all Java APIs that interface with host ...
(JNDI)
*
Interprocess Communication
In computer science, inter-process communication or interprocess communication (IPC) refers specifically to the mechanisms an operating system provides to allow the processes to manage shared data. Typically, applications can use IPC, categori ...
using
RMI-IIOP RMI-IIOP (read as "RMI over IIOP") denotes the Java Remote Method Invocation (RMI) interface over the Internet Inter-Orb Protocol (IIOP), which delivers Common Object Request Broker Architecture (CORBA) distributed computing
A distributed syst ...
and
Web services
*
Security
Security is protection from, or resilience against, potential harm (or other unwanted coercive change) caused by others, by restraining the freedom of others to act. Beneficiaries (technically referents) of security may be of persons and social ...
(
JCE and
JAAS)
*
Deployment
Deployment may refer to:
Engineering and software Concepts
* Blue-green deployment, a method of installing changes to a web, app, or database server by swapping alternating production and staging servers
* Continuous deployment, a software en ...
of
software component
Component-based software engineering (CBSE), also called component-based development (CBD), is a branch of software engineering that emphasizes the separation of concerns with respect to the wide-ranging functionality available throughout a give ...
s in an application server
Additionally, the Jakarta Enterprise Beans specification defines the roles played by the EJB container and the EJBs as well as how to deploy the EJBs in a container. Note that the EJB specification does not detail how an application server provides persistence (a task delegated to the JPA specification), but instead details how business logic can easily integrate with the persistence services offered by the application server.
History
Businesses found that using EJBs to encapsulate business logic brought a performance penalty. This is because the original specification allowed only for remote method invocation through
CORBA
The Common Object Request Broker Architecture (CORBA) is a standard defined by the Object Management Group (OMG) designed to facilitate the communication of systems that are deployed on diverse platforms. CORBA enables collaboration between sys ...
(and optionally other protocols), even though the large majority of business applications actually do not require this
distributed computing
A distributed system is a system whose components are located on different computer network, networked computers, which communicate and coordinate their actions by message passing, passing messages to one another from any system. Distributed com ...
functionality. The EJB 2.0 specification addressed this concern by adding the concept of local interfaces which could be called directly without performance penalties by applications that were not distributed over multiple servers.
The EJB 3.0 specification (
JSR 220) was a departure from its predecessors, following a new light-weight paradigm. EJB 3.0 shows an influence from
Spring
Spring(s) may refer to:
Common uses
* Spring (season), a season of the year
* Spring (device), a mechanical device that stores energy
* Spring (hydrology), a natural source of water
* Spring (mathematics), a geometric surface in the shape of a ...
in its use of plain Java objects, and its support for
dependency injection to simplify configuration and integration of heterogeneous systems. EJB 3.0 along with the other version of the EJB can be integrated with
MuleSoft
MuleSoft, LLC. is a software company headquartered in San Francisco, California, that provides integration software for connecting applications, data and devices. Started in 2006, the company's Anypoint Platform of integration products is designe ...
-v4 using MuleSoft certifie
PlektonLabs EJB Connector Gavin King, the creator of Hibernate, participated in the EJB 3.0 process and is an outspoken advocate of the technology. Many features originally in Hibernate were incorporated in the
Java Persistence API
Jakarta Persistence (JPA; formerly Java Persistence API) is a Jakarta EE application programming interface specification that describes the management of relational data in enterprise Java applications.
Persistence in this context covers three a ...
, the replacement for
entity beans in EJB 3.0. The EJB 3.0 specification relies heavily on the use of
annotations
An annotation is extra information associated with a particular point in a document or other piece of information. It can be a note that includes a comment or explanation. Annotations are sometimes presented in the margin of book pages. For anno ...
(a feature added to the Java language with its 5.0 release) and
convention over configuration
Convention over configuration (also known as coding by convention) is a software design paradigm used by software frameworks that attempts to decrease the number of decisions that a developer using the framework is required to make without necessa ...
to enable a much less verbose coding style. Accordingly, in practical terms EJB 3.0 is much more lightweight and nearly a completely new API, bearing little resemblance to the previous EJB specifications.
Example
The following shows a basic example of what an EJB looks like in code:
@Stateless
public class CustomerService
The above defines a service class for persisting a Customer object (via
O/R mapping). The EJB takes care of managing the persistence context and the addCustomer() method is transactional and thread-safe by default. As demonstrated, the EJB focuses only on business logic and persistence and knows nothing about any particular presentation.
Such an EJB can be used by a class in e.g. the web layer as follows:
@Named
@RequestScoped
public class CustomerBacking
The above defines a
JavaServer Faces
Jakarta Faces, formerly Jakarta Server Faces and JavaServer Faces (JSF) is a Java specification for building component-based user interfaces for web applications and was formalized as a standard through the Java Community Process being part of t ...
(JSF) backing bean in which the EJB is injected by means of the @EJB annotation. Its addCustomer method is typically bound to some UI component, such as a button. Contrary to the EJB, the backing bean does not contain any business logic or persistence code, but delegates such concerns to the EJB. The backing bean does know about a particular presentation, of which the EJB had no knowledge.
Types of Enterprise Beans
An EJB container holds two major types of beans:
* Session Beans that can be either "Stateful", "Stateless" or "Singleton" and can be accessed via either a Local (same JVM) or Remote (different JVM) interface or directly without an interface, in which case local semantics apply. All session beans support asynchronous execution for all views (local/remote/no-interface).
* Message Driven Beans (MDBs, also known as Message Beans). MDBs also support asynchronous execution, but via a messaging paradigm.
Session beans
Stateful Session Beans
Stateful Session Beans are business objects having
state
State may refer to:
Arts, entertainment, and media Literature
* ''State Magazine'', a monthly magazine published by the U.S. Department of State
* ''The State'' (newspaper), a daily newspaper in Columbia, South Carolina, United States
* ''Our S ...
: that is, they keep track of which calling client they are dealing with throughout a session and thus access to the bean instance is strictly limited to only one client at a time.
[JSR 318, 4.10.3, http://jcp.org/en/jsr/detail?id=318] If concurrent access to a single bean is attempted anyway the container serializes those requests, but via the @AccessTimeout annotation the container can instead throw an exception. Stateful session beans' state may be persisted (passivated) automatically by the container to free up memory after the client hasn't accessed the bean for some time. The JPA extended persistence context is explicitly supported by Stateful Session Beans.
; ''Examples'':
* Checking out in a web store might be handled by a stateful session bean that would use its state to keep track of where the customer is in the checkout process, possibly holding locks on the items the customer is purchasing (from a system architecture's point of view, it would be less ideal to have the client manage those locks).
Stateless Session Beans
Stateless Session Beans are business objects that do not have state associated with them. However, access to a single bean instance is still limited to only one client at a time,
concurrent
Concurrent means happening at the same time. Concurrency, concurrent, or concurrence may refer to:
Law
* Concurrence, in jurisprudence, the need to prove both ''actus reus'' and ''mens rea''
* Concurring opinion (also called a "concurrence"), a ...
access to the bean is prohibited.
If concurrent access to a single bean is attempted, the container simply routes each request to a different instance. This makes a stateless session bean automatically thread-safe. Instance variables can be used during a single method call from a client to the bean, but the contents of those instance variables are not guaranteed to be preserved across different client
method
Method ( grc, μέθοδος, methodos) literally means a pursuit of knowledge, investigation, mode of prosecuting such inquiry, or system. In recent centuries it more often means a prescribed process for completing a task. It may refer to:
*Scien ...
calls. Instances of Stateless Session beans are typically pooled. If a second client accesses a specific bean right after a method call on it made by a first client has finished, it might get the same instance. The lack of overhead to maintain a conversation with the calling client makes them less resource-intensive than stateful beans.
; ''Examples'':
* Sending an e-mail to customer support might be handled by a stateless bean, since this is a one-off operation and not part of a multi-step process.
* A user of a website clicking on a "keep me informed of future updates" box may trigger a call to an asynchronous method of the session bean to add the user to a list in the company's database (this call is asynchronous because the user does not need to wait to be informed of its success or failure).
* Fetching multiple independent pieces of data for a website, like a list of products and the history of the current user might be handled by asynchronous methods of a session bean as well (these calls are asynchronous because they can execute in
parallel
Parallel is a geometric term of location which may refer to:
Computing
* Parallel algorithm
* Parallel computing
* Parallel metaheuristic
* Parallel (software), a UNIX utility for running programs in parallel
* Parallel Sysplex, a cluster of IBM ...
that way, which potentially increases performance). In this case, the asynchronous method will return
Futureinstance.
Singleton Session Beans
Singleton Session Beans are business objects having a global shared state within a JVM. Concurrent access to the one and only bean instance can be controlled by the container (Container-managed concurrency, CMC) or by the bean itself (Bean-managed concurrency, BMC). CMC can be tuned using the @Lock annotation, that designates whether a read lock or a write lock will be used for a method call. Additionally, Singleton Session Beans can explicitly request to be instantiated when the EJB container starts up, using the @Startup annotation.
; ''Examples'':
* Loading a global daily price list that will be the same for every user might be done with a singleton session bean, since this will prevent the application having to do the same query to a database over and over again...
Message driven beans
Message Driven Beans are business objects whose execution is triggered by messages instead of by method calls. The Message Driven Bean is used among others to provide a high level ease-of-use abstraction for the lower level JMS (
Java Message Service
The Jakarta Messaging API (formerly Java Message Service or JMS API) is a Java application programming interface (API) for message-oriented middleware. It provides generic messaging models, able to handle the producer–consumer problem, that can ...
) specification. It may subscribe to JMS message queues or message topics, which typically happens via the activationConfig attribute of the @MessageDriven annotation. They were added in EJB to allow event-driven processing. Unlike session beans, an MDB does not have a client view (Local/Remote/No-interface), i. e. clients cannot look-up an MDB instance. An MDB just listens for any incoming message on, for example, a JMS queue or topic and processes them automatically. Only JMS support is required by the Java EE spec, but Message Driven Beans can support other messaging protocols. Such protocols may be asynchronous but can also be synchronous. Since session beans can also be synchronous or asynchronous, the prime difference between session- and message driven beans is not the synchronicity, but the difference between (object oriented)
method
Method ( grc, μέθοδος, methodos) literally means a pursuit of knowledge, investigation, mode of prosecuting such inquiry, or system. In recent centuries it more often means a prescribed process for completing a task. It may refer to:
*Scien ...
calling and
messaging
A message is a discrete unit of communication intended by the source for consumption by some recipient or group of recipients. A message may be delivered by various means, including courier, telegraphy, carrier pigeon and electronic bus.
A ...
.
; ''Examples'':
* Sending a configuration update to multiple nodes might be done by sending a JMS message to a 'message topic' and could be handled by a Message Driven Bean listening to this topic (the message paradigm is used here since the sender does not need to know the number of consumers, their location, or even their exact type).
* Submitting a job to a work cluster might be done by sending a JMS message to a 'message queue' and could also be handled by a Message Driven Bean, but this time listening to a queue (the message paradigm and the queue is used, since the sender doesn't have to care which worker executes the job, but it does need assurance that a job is only executed once).
* Processing timing events from th
Quartz schedulercan be handled by a Message Driven Bean; when a Quartz ''trigger'' fires, the MDB is automatically invoked. Since Java EE doesn't know about Quartz by default, a
JCA resource adapter would be needed and the MDB would be annotated with a reference to this.
Execution
EJBs are deployed in an EJB container, typically within an
application server
An application server is a server that hosts applications or software that delivers a business application through a communication protocol.
An application server framework is a service layer model. It includes software components available to a ...
. The specification describes how an EJB interacts with its container and how client code interacts with the container/EJB combination. The EJB classes used by applications are included in the package. (The package is a
service provider interface Service provider interface (SPI) is an API intended to be implemented or extended by a third party. It can be used to enable framework extension and replaceable components.
Details
From Java documentation:
The concept can be extended to other pla ...
used only by EJB container implementations.)
Clients of EJBs do not instantiate those beans directly via Java's new operator, but instead have to obtain a reference via the EJB container. This reference is usually not a reference to the implementation bean itself, but to a
proxy
Proxy may refer to:
* Proxy or agent (law), a substitute authorized to act for another entity or a document which authorizes the agent so to act
* Proxy (climate), a measured variable used to infer the value of a variable of interest in climate ...
, which either dynamically implements the local or remote business interface that the client requested or dynamically implements a sub-type of the actual bean. The proxy can then be directly cast to the interface or bean. A client is said to have a 'view' on the EJB, and the local interface, remote interface and bean type itself respectively correspond with the local view, remote view and no-interface view.
This proxy is needed in order to give the EJB container the opportunity to transparently provide cross-cutting (
AOP-like) services to a bean like transactions, security, interceptions, injections, and remoting. As an example, a client invokes a method on a proxy, which will first start a transaction with the help of the EJB container and then call the actual bean method. When the bean method returns, the proxy ends the transaction (i.e. by committing it or doing a rollback) and transfers control back to the client.
The EJB Container is responsible for ensuring the client code has sufficient access rights to an EJB. Security aspects can be declaratively applied to an EJB via annotations.
Transactions
EJB containers must support both container managed
ACID
In computer science, ACID ( atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee data validity despite errors, power failures, and other mishaps. In the context of databases, a sequ ...
transactions and bean managed transactions.
Container-managed transactions (CMT) are by default active for calls to session beans. That is, no explicit configuration is needed. This behavior may be declaratively tuned by the bean via annotations and if needed such configuration can later be overridden in the deployment descriptor. Tuning includes switching off transactions for the whole bean or specific methods, or requesting alternative strategies for transaction propagation and starting or joining a transaction. Such strategies mainly deal with what should happen if a transaction is or isn't already in progress at the time the bean is called. The following variations are supported:
Alternatively, the bean can also declare via an annotation that it wants to handle transactions programmatically via the
JTA API. This mode of operation is called Bean Managed Transactions (BMT), since the bean itself handles the transaction instead of the container.
Events
JMS (
Java Message Service
The Jakarta Messaging API (formerly Java Message Service or JMS API) is a Java application programming interface (API) for message-oriented middleware. It provides generic messaging models, able to handle the producer–consumer problem, that can ...
) is used to send messages from beans to clients, to let clients receive asynchronous messages from these beans.
MDBs can be used to receive messages from clients asynchronously using either a JMS
Queue or a Topic.
Naming and directory services
As an alternative to injection, clients of an EJB can obtain a reference to the session bean's proxy object (the EJB stub) using
Java Naming and Directory Interface (JNDI). This alternative can be used in cases where injection is not available, such as in non-managed code or standalone remote Java SE clients, or when it's necessary to programmatically determine which bean to obtain.
JNDI names for EJB session beans are assigned by the EJB container via the following scheme:
''(entries in square brackets denote optional parts)''
A single bean can be obtained by any name matching the above patterns, depending on the 'location' of the client. Clients in the same module as the required bean can use the module scope and larger scopes, clients in the same application as the required bean can use the app scope and higher, etc.
E.g. code running in the same module as the CustomerService bean ''(as given by the example shown earlier in this article)'' could use the following code to obtain a (local) reference to it:
CustomerServiceLocal customerService =
(CustomerServiceLocal) new InitialContext().lookup("java:module/CustomerService");
Remoting/distributed execution
For communication with a client that's written in the Java programming language a session bean can expose a remote-view via an @Remote annotated interface. This allows those beans to be called from clients in other
JVM
A Java virtual machine (JVM) is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode. The JVM is detailed by a specification that formally describes ...
s which themselves may be located on other (remote) systems. From the point of view of the EJB container, any code in another JVM is remote.
Stateless- and Singleton session beans may also expose a "web service client view" for remote communication via
WSDL
The Web Services Description Language (WSDL ) is an XML-based interface description language that is used for describing the functionality offered by a web service. The acronym is also used for any specific WSDL description of a web service (also ...
and
SOAP
Soap is a salt of a fatty acid used in a variety of cleansing and lubricating products. In a domestic setting, soaps are surfactants usually used for washing, bathing, and other types of housekeeping. In industrial settings, soaps are use ...
or plain XML. This follows the
JAX-RPC
Jakarta XML RPC (JAX-RPC; formerly Java API for XML Based RPC) allows a Jakarta EE application to invoke a Java-based web service with a known description while still being consistent with its WSDL description. JAX-RPC is one of the Java XML progr ...
and
JAX-WS
The Jakarta XML Web Services (JAX-WS; formerly Java API for XML Web Services) is a Jakarta EE Application programming interface, API for creating web services, particularly SOAP services. JAX-WS is one of the Java XML programming APIs.
Overview
...
specifications. JAX-RPC support however is proposed for future removal.
[JSR 318, 2.7, http://jcp.org/en/jsr/detail?id=318] To support JAX-WS, the session bean is annotated with the @WebService annotation, and methods that are to be exposed remotely with the @WebMethod annotation..
Although the EJB specification does not mention exposure as RESTful web services in any way and has no explicit support for this form of communication, the
JAX-RS
Jakarta RESTful Web Services, (JAX-RS; formerly Java API for RESTful Web Services) is a Jakarta EE API specification that provides support in creating web services according to the Representational State Transfer (REST) architectural pattern. ...
specification does explicitly support EJB. Following the JAX-RS spec, Stateless- and Singleton session beans can be root resources via the @Path annotation and EJB business methods can be mapped to resource methods via the @GET, @PUT, @POST and @DELETE annotations. This however does not count as a "web service client view", which is used exclusively for JAX-WS and JAX-RPC.
Communication via web services is typical for clients not written in the Java programming language, but is also convenient for Java clients who have trouble reaching the EJB server via a firewall. Additionally, web service based communication can be used by Java clients to circumvent the arcane and ill-defined requirements for the so-called "client-libraries"; a set of jar files that a Java client must have on its class-path in order to communicate with the remote EJB server. These client-libraries potentially conflict with libraries the client may already have (for instance, if the client itself is also a full Java EE server) and such a conflict is deemed to be very hard or impossible to resolve.
Legacy
Home interfaces and required business interface
With EJB 2.1 and earlier, each EJB had to provide a Java implementation
class
Class or The Class may refer to:
Common uses not otherwise categorized
* Class (biology), a taxonomic rank
* Class (knowledge representation), a collection of individuals or objects
* Class (philosophy), an analytical concept used differentl ...
and two Java interfaces. The EJB container created instances of the Java implementation class to provide the EJB implementation. The Java interfaces were used by client code of the EJB.
Required deployment descriptor
With EJB 2.1 and earlier, the EJB specification required a deployment descriptor to be present. This was needed to implement a mechanism that allowed EJBs to be
deployed in a consistent manner regardless of the specific EJB platform that was chosen. Information about how the bean should be deployed (such as the name of the home or remote interfaces, whether and how to store the bean in a database, etc.) had to be specified in the deployment descriptor.
The
deployment descriptor A deployment descriptor (DD) refers to a configuration file for an artifact that is deployed to some container/engine.
In the Java Platform, Enterprise Edition, a deployment descriptor describes how a component, module or application (such as a w ...
is an
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing arbitrary data. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. T ...
document having an entry for each EJB to be deployed. This XML document specifies the following information for each EJB:
* Name of the Home interface
* Java class for the Bean (business object)
* Java interface for the Home interface
* Java interface for the business object
* Persistent store (only for Entity Beans)
* Security roles and permissions
* Stateful or Stateless (for Session Beans)
Old EJB containers from many vendors required more deployment information than that in the EJB specification. They would require the additional information as separate XML files, or some other configuration file format. An EJB platform vendor generally provided their own tools that would read this deployment descriptor, and possibly generated a set of classes that would implement the now deprecated Home and Remote interfaces.
Since EJB 3.0
JSR 220, the XML descriptor is replaced by
Java annotation
In the Java computer programming language, an annotation is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and Java packages may be annotated. Like Javadoc tags, Java annotations can ...
s set in the Enterprise Bean implementation (at source level), although it is still possible to use an XML descriptor instead of (or in addition to) the annotations. If an XML descriptor and annotations are both applied to the same attribute within an Enterprise Bean, the XML definition overrides the corresponding source-level annotation, although some XML elements can also be additive (e.g., an activation-config-property in XML with a different name than already defined via an @ActivationConfigProperty annotation will be added instead of replacing all existing properties).
Container variations
Starting with EJB 3.1, the EJB specification defines two variants of the EJB container; a full version and a limited version. The limited version adheres to a
proper subset
In mathematics, set ''A'' is a subset of a set ''B'' if all elements of ''A'' are also elements of ''B''; ''B'' is then a superset of ''A''. It is possible for ''A'' and ''B'' to be equal; if they are unequal, then ''A'' is a proper subset of ...
of the specification called EJB 3.1 Lite and is part of
Java EE 6's web profile (which is itself a subset of the full Java EE 6 specification).
EJB 3.1 Lite excludes support for the following features:
* Remote interfaces
* RMI-IIOP Interoperability
* JAX-WS Web Service Endpoints
* EJB Timer Service (@Schedule, @Timeout)
* Asynchronous session bean invocations (@Asynchronous)
* Message-driven beans
EJB 3.2 Lite excludes less features. Particularly it no longer excludes @Asynchronous and @Schedule/@Timeout, but for @Schedule it does not support the "persistent" attribute that full EJB 3.2 does support. The complete excluded list for EJB 3.2 Lite is:
* Remote interfaces
* RMI-IIOP Interoperability
* JAX-WS Web Service Endpoints
* Persistent timers ("persistent" attribute on @Schedule)
* Message-driven beans
Version history
EJB 4.0, final release (2020-05-22)
Jakarta Enterprise Beans 4.0 as a part of Jakarta EE 9, was a tooling release that mainly moved API package names from the top level package to the top level package.
Other changes included removal of deprecated APIs that were pointless to move to the new top level package and the removal of features that depended on features that were removed from Java or elsewhere in Jakarta EE 9. The following APIs were removed:
* methods relying on which has been removed from the Java 14.
* methods relying on
Jakarta XML RPC
Jakarta XML RPC (JAX-RPC; formerly Java API for XML Based RPC) allows a Jakarta EE application to invoke a Java-based web service with a known description while still being consistent with its WSDL description. JAX-RPC is one of the Java XML progr ...
to reflect the removal of XML RPC from the Jakarta EE 9 Platform.
* deprecated method.
* "Support for Distributed Interoperability" to reflect the removal of CORBA from Java 11 and the Jakarta EE 9 Platform.
Other minor changes include marking the Enterprise Beans 2.x API Group as "Optional" and making the annotation repeatable.
EJB 3.2.6, final release (2019-08-23)
Jakarta Enterprise Beans 3.2 as a part of Jakarta EE 8, and despite still using "EJB" abbreviation, this set of APIs has been officially renamed to "Jakarta Enterprise Beans" by the
Eclipse Foundation
The Eclipse Foundation AISBL is an independent, Europe-based not-for-profit corporation that acts as a steward of the Eclipse open source software development community, with legal jurisdiction in the European Union. It is an organization suppo ...
so as not to tread on the Oracle "Java" trademark.
EJB 3.2, final release (2013-05-28)
JSR 345 Enterprise JavaBeans 3.2 was a relatively minor release that mainly contained specification clarifications and lifted some restrictions that were imposed by the spec but over time appeared to serve no real purpose. A few existing full EJB features were also demanded to be in EJB 3 lite and functionality that was proposed to be pruned in EJB 3.1 was indeed pruned (made optional).
The following features were added:
* Passivation of a stateful session bean can be deactivated via attribute on @Stateful annotation (passivationCapable = false)
* TimerService can retrieve all active timers in the same EJB module (could previously only retrieve timers for the bean in which the TimerService was called)
* Lifecycle methods (e.g. @PostConstruct) can be transactional for stateful session beans using the existing @TransactionAttribute annotation
* Autocloseable interface implemented by embeddable container
EJB 3.1, final release (2009-12-10)
JSR 318 The purpose of the Enterprise JavaBeans 3.1 specification is to further simplify the EJB architecture by reducing its complexity from the developer's point of view, while also adding new functionality in response to the needs of the community:
* Local view without interface (No-interface view)
*
.war packaging of EJB components
* EJB Lite: definition of a subset of EJB
* Portable EJB Global
JNDI
The Java Naming and Directory Interface (JNDI) is a Java API for a directory service that allows Java software clients to discover and look up data and resources (in the form of Java objects) via a name. Like all Java APIs that interface with host ...
Names
*
Singleton
Singleton may refer to:
Sciences, technology Mathematics
* Singleton (mathematics), a set with exactly one element
* Singleton field, used in conformal field theory Computing
* Singleton pattern, a design pattern that allows only one instance o ...
s (Singleton Session Beans)
* Application Initialization and Shutdown Events
* EJB Timer Service Enhancements
* Simple
Asynchrony (@Asynchronous for session beans)
EJB 3.0, final release (2006-05-11)
JSR 220- ''Major changes'':
This release made it much easier to write EJBs, using 'annotations' rather than the complex 'deployment descriptors' used in version 2.x. The use of home and remote interfaces and the ejb-jar.xml file were also no longer required in this release, having been replaced with a business interface and a bean that implements the interface.
EJB 2.1, final release (2003-11-24)
JSR 153- ''Major changes'':
*
Web service support (new): stateless session beans can be invoked over
SOAP
Soap is a salt of a fatty acid used in a variety of cleansing and lubricating products. In a domestic setting, soaps are surfactants usually used for washing, bathing, and other types of housekeeping. In industrial settings, soaps are use ...
/
HTTP
The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, ...
. Also, an EJB can easily access a Web service using the new service reference.
* EJB timer service (new): Event-based mechanism for invoking EJBs at specific times.
* Message-driven beans accepts messages from sources other than
JMS.
* Message destinations (the same idea as EJB references, resource references, etc.) has been added.
* EJB query language (EJB-QL) additions: ORDER BY, AVG, MIN, MAX, SUM, COUNT, and MOD.
*
XML schema
An XML schema is a description of a type of Extensible Markup Language, XML document, typically expressed in terms of constraints on the structure and content of documents of that type, above and beyond the basic syntactical constraints imposed ...
is used to specify deployment descriptors, replaces
DTDs
EJB 2.0, final release (2001-08-22)
JSR 19- ''Major changes'':
''Overall goals'':
* The standard component architecture for building ''distributed'' object-oriented business applications in
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
.
* Make it possible to build distributed applications by combining components developed using tools from ''different vendors''.
* Make it easy to write (enterprise) applications: Application developers will not have to understand low-level transaction and state management details, multi-threading, connection pooling, and other complex low-level APIs.
* Will follow the "Write Once, Run Anywhere" philosophy of
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
. An enterprise Bean can be developed once, and then deployed on multiple platforms without recompilation or source code modification.
* Address the development, deployment, and runtime aspects of an enterprise application’s life cycle.
* Define the contracts that enable tools from multiple vendors to develop and deploy components that can interoperate at runtime.
* Be compatible with existing server platforms. Vendors will be able to extend their existing products to support EJBs.
* Be compatible with other
Java
Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's List ...
APIs.
* Provide interoperability between enterprise Beans and Java EE components as well as non-Java programming language applications.
* Be compatible with the CORBA protocols (RMI-IIOP).
EJB 1.1, final release (1999-12-17)
''Major changes'':
* XML deployment descriptors
* Default JNDI contexts
* RMI over IIOP
* Security - role driven, not method driven
* Entity Bean support - mandatory, not optional
''Goals'' for Release 1.1:
* Provide better support for application assembly and deployment.
* Specify in greater detail the responsibilities of the individual EJB roles.
EJB 1.0 (1998-03-24)
Announced at
JavaOne 1998,
Sun's third Java developers conference (March 24 through 27)
''Goals'' for Release 1.0:
* Defined the distinct "EJB Roles" that are assumed by the component architecture.
* Defined the client view of enterprise Beans.
* Defined the enterprise Bean developer’s view.
* Defined the responsibilities of an EJB Container provider and server provider; together these make up a system that supports the deployment and execution of enterprise Beans.
References
External links
*
*
EJB 3.0 API JavadocsEJB (3.0) GlossaryEJB FAQJSR 345(EJB 3.2)
JSR 318(EJB 3.1)
JSR 220(EJB 3.0)
JSR 153(EJB 2.1)
JSR 19(EJB 2.0)
*
ttp://r4r.co.in/java/ejb/ Client invokes an EJB
{{DEFAULTSORT:Enterprise Javabean
Java enterprise platform
Java specification requests
Java platform software