Show TOC

Background documentationEJB Overview Locate this document in the navigation structure

 

Enterprise JavaBeans (EJB) is one of the most important components of the Java EE Platform.

EJB components represent the business logic in scalable, multilayer, distributed applications. They

simplify application developers' work, allowing them to focus on their business logic. Complex matters such as security, transactions and life cycle events are handled by the EJB Container and developers only need to configure what they would like to use.

The development process of EJB is as simple as implementing the source code of the beans, packaging them into JAR files, and deploying them on the server. If you use EJB 3.0 you can optionally describe the beans in the ejb-jar.xml or use annotations instead. If you use EJB 2.x you have to use the deployment descriptor.

EJB 3.0

The SAP NetWeaver Application Server is compliant with EJB 3.0 and all previous versions of the EJB specification. When you develop new EJB applications, we recommend that you use Enterprise JavaBeans 3.0 specification.

Types of Enterprise Beans

There are three types of beans - stateful, stateless and message-driven beans. Each type is suitable for different use cases.

Use stateful session beans when you want to preserve the bean state between method invocations.

Stateless session beans do not hold the state between method invocations. This has several advantages in the cases when the state between the method invocation is not needed:

  • Less server resources consumption

  • Faster access.

Message-driven beans are used in asynchronous communication scenarios such as receiving JMS messages.

More information:

Life Cycle

The life cycle of the beans depends on their type. Stateless and message-driven beans have two states - active and not existing - while stateful beans have a third state, they can be passivated.

The EJB Container creates and manages the beans' instances. If your application logic needs to be aware of the life cycle events, you have to provide callback methods so that the EJB Container calls them at the appropriate moment.

  • Life cycle of stateful session beans' instances

    This graphic is explained in the accompanying text.

  • Life cycle of stateless session beans' instances

    This graphic is explained in the accompanying text.

  • Life cycle of message-driven beans' instances

    This graphic is explained in the accompanying text.

Dependency Injection

In EJB 3.0 using annotations you can inject dependencies to obtain a resource in a bean or a reference to another bean.

More information: Using Dependency Injection

EJB Lookup Scheme

To access an enterprise bean from nonstandard Java EE components that cannot take advantage of the JNDI environment, you have to use a new format of the lookup strings, called EJB lookup scheme.

More information: Accessing Enterprise JavaBeans from Remote Clients

Java Persistence API (JPA)

Persistency has evolved in Java Persistence API (JPA). The old fashioned entity beans are still supported but for new development, we recommend that you use the JPA specification.

In EJB 3.0 the entity beans are replaced by Plain Old Java Objects (POJOs), which are managed through the Java Persistence API (JPA).

More information: Using Java Persistence API (JPA)