Using EJB Types

You can define the following types of EJB components:

Type

Definition

Entity Beans

Designed to represent data in the database; they wrap data with business object semantics, read and update data automatically. Entity beans include: CMP (Container Managed Persistence) With CMP Entity Beans, persistence is handled by the component server (also known as Container) BMP (Bean Managed Persistence) With BMP Entity Beans, persistence management is left to the bean developer

Session Beans (Stateful and Stateless)

Encapsulate business logic and provide a single entry point for client users. A session bean will usually manage, and provide indirect access to several entity beans. Using this architecture, network traffic can be substantially reduced. There are Stateful and Stateless beans (see below)

Message Driven Beans

Anonymous beans that cannot be referenced by a given client, but rather respond to JMS asynchronous messages. Like Session Beans, they provide a way of encapsulating business logic on the server side

Entity Beans

Entity beans are used to represent underlying objects. The most common application for entity beans is their representation of data in a relational database. A simple entity bean can be defined to represent a database table where each instance of the bean represents a specific row. More complex entity beans can represent views of joined tables in a database. One instance represents a specific customer and all of that customer's orders and order items.

The code generated is different depending on the type of Entity Bean (Container Managed Persistence or Bean Managed Persistence).

Stateful and Stateless Session Beans

A session bean is an EJB in which each instance of a session bean is created through its home interface and is private to the client connection. The session bean instance cannot be easily shared with other clients, this allows the session bean to maintain the client's state. The relationship between the client and the session bean instance is one-to-one.

Stateful session beans maintain conversational state when used by a client. A conversational state is not written to a database, it is a state kept in memory while a client uses a session.

Stateless session beans do not maintain any conversational state. Each method is independent, and uses only data passed in its parameters.

Message Driven Beans

They are stateless, server side components with transactional behavior that process asynchronous messages delivered via the Java Message Service (JMS). Applications use asynchronous messaging to communicate by exchanging messages that leave senders independent from receivers.


Created October 7, 2009. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com