eWebProgrammer eweb  





Entity Beans   «Prev  Next»
Lesson 3Characteristics of entity beans
ObjectiveDescribe the characteristics of entity beans.

In-memory representation of an entity bean

This lesson describes the main features of an entity bean. Entity beans provide an in-memory object representation of an entity that is composed of transactional data in a database, or of any entity that has a unique identity and a persistent state. They allow shared access from multiple clients. If one client is currently accessing a method of an entity bean instance, all other concurrent requests will be queued up and executed in order as soon as each method call terminates. If the method executes within a transaction context, no other client will get access to the instance until the transaction is rolled back or committed.
Unique identity
Every entity bean has a unique primary key that is used to identify it. The value of the primary key is usually the primary key in the database or object store.
Surviving the crash of a container
Entity beans survive the crash of the container, unlike session beans, which do not. The entity bean instance is really a representation of the underlying persistent data. That is its purpose. The session bean instance, on the other hand, is designed to be an extension of the client that created it. If the container crashes and is restarted, the container can recreate the entity bean instances as and when clients need them. The crash is almost transparent to the client. We use the word "almost," because the client may receive an exception.


Creation and removal
Entity bean instances can be long-lived. They live as long as the data they represent exists. If the bean instance is removed, the underlying data also is removed. When the client creates an instance of an entity bean, the underlying persistent data is created and written to the persistent store.
Lives in a container
Entity beans live inside a container. The container provides security, concurrency, transactions, persistence, and other services. These other services may include Object Relational mapping that is vendor specific.
The next lesson introduces the primary key and issues concerning the identity of an entity bean.