Enterprise JavaBeans

The Enterprise JavaBeans specification is one of the several Java APIs in the Java 2 Platform, Enterprise Edition. The specification details how an application server provides server-side objects known as Enterprise JavaBeans, or EJBs, with:

  • remote communication using CORBA
  • persistence
  • transactions
  • concurrency control
  • events using JMS (Java messaging service)
  • naming and directory services
  • security
  • deployment of components in an application server

Additionally, the Enterprise JavaBean specification defines the roles played by the EJB container and the EJBs as well as how to deploy the EJBs in a container.

Contents

Enterprise JavaBean Basics

EJBs are deployed in an EJB container within the application server. The specification describes how an EJB interacts with its container and how client code interacts with the container/EJB combination.

Each EJB must provide a Java implementation class and two Java interfaces. The EJB container will create instances of the Java implementation class1 to provide the EJB implementation. The Java interfaces are used by client code of the EJB. The two interfaces, referred to as the home and remote interfaces, specify the signatures of the EJB's remote methods. The remote methods are split into two groups:

  • methods that are not tied to a specific instance, e.g. those used to create an EJB instance or to find an existing entity EJB (see EJB Types below). These are declared by the home interface.
  • methods that are tied to a specific instance. These are placed in the remote interface.

As these are merely Java interfaces and not concrete classes, the EJB container is required to generate classes for these interfaces that will act as a proxy in the client. Client code invokes a method on the generated proxies which in turn places the method arguments into a message and sends the message to the EJB server. The proxies use RMI-IIOP to communicate with the EJB server.

The server will invoke a corresponding method on an instance of the Java implementation class to handle the remote method invocation. The image below shows a typical Java client interacting remotely with an EJB in its EJB container using remote method invocations and JMS messages.

Missing image
J2eeejbcontainer.gif
image:j2eeejbcontainer.gif

Home Interface

As stated previously, the Home Interface allows client code to manipulate certain class methods of the EJB, that is, methods that are not associated with any particular instance.
The EJB 1.1 specification fixes the kind of class methods that can be defined to either be methods to create an EJB or to find an existing EJB if it is an entity bean..
The EJB 2.0 specification allows application developers to define new class methods beyond create, delete and find.

Remote Interface

The Remote Interface specifies the instance specific methods of the bean class.

EJB Implementation Class

EJB implementation classes are supplied by the application developers. They implement business logic or hold the business data for the object interface. i.e. they implement all the methods specified by the remote interface and potentially some of those specified by the home interface.

Correspondence between Interface Methods and Implementation Methods

Method invocations on the home interface are dispatched to corresponding method on the bean implementation class with the prefix 'ejb' added and with the first letter of the home interface method capitalized and having exactly the same argument types.

Method invocations on the remote interface are dispatched to corresponding implementation method having the same name and arguments.

EJB Types

An EJB container can hold four major categories of beans; they are:

  • Stateless Session Beans
  • Stateful Session Beans
  • Entity Beans
  • Message Driven Beans (or Message Beans)

Stateless session beans are distributed objects that do not have state associated with them thus allowing concurrent access to the bean. The contents of instance variables are not guaranteed to be preserved across method calls.

Stateful session beans are distributed objects having state. The state is not persisted, but access to the bean is limited to only one client.

Entity beans are distributed objects having persistent state. The persistent state may or may not be managed by the bean itself. Beans in which their container manages the persistent state are said to be using Container Managed Persistence or CMP, whereas beans that manage their own state are said to be using Bean Managed Persistence.

Message Beans are distributed objects that respond to JMS messages. These beans were added in the EJB 2.0 specification to allow event driven beans.

Remote Communication

The EJB specification requires that EJB containers support accessing the EJBs using RMI-IIOP. EJBs may be accessed from any CORBA application.

Persistence

EJB containers are required to support container managed persistence (CMP) as well as bean managed persistence (BMP).

Transactions

EJB containers are required to support container managed transactions as well as bean managed transactions. Container managed transactions use a declarative syntax for specifying transactions in the deployment descriptor.

Events

JMS is used to send messages from the beans to client objects in order to allow clients to receive asynchronous messages from these beans.

Naming and Directory services

Clients of the enterprise Java bean locate the Home Interface implementation object using JNDI. The Home interface may also be found using the CORBA name service. From the home interface, client code can find entity beans, as well as create and delete existing EJBs.

Security

The EJB container is responsible for ensuring the client code has sufficient access rights to an EJB.

Deploying EJBs

The EJB Specification also defines a mechanism which allows enterprise Java beans to be deployed in a similar manner regardless of the specific EJB platform that is 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. are specified in the deployment descriptor.

The deployment descriptor is an XML 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
  • Java interface for the home interface
  • Java interface for the object
  • Persistent Store
  • Security Roles and Permissions

However it should be noted that many EJB containers require additional deployment information other than what is specified in the EJB specification. These vendors will require the additional information to be provided either as separate XML files or some other configuration file format. Further, each EJB platform vendor generally provides their own tools that will read this deployment descriptor and possibly generate a set of classes that will implement the home and remote interfaces mentioned earlier.

Recommended Programming Model

In the recommended programming model from Sun, stateful and stateless session beans are used for business logic whereas entity beans are used for business data.

External links

es:Enterprise JavaBeans fr:Enterprise JavaBeans ja:Enterprise JavaBeans zh:EJB

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools