Library Zone Articles
External Articles
Byte Size

Discovery Zone Catalogue
Diary
Links
Bookstore
Interactive Zone Ask the Gurus
Discussion Groups
Newsletters
Feedback
Etc Cartoons
Humour
COMpetition
Advertising ASP Web Ring ASP Web Ring
Power your site with idr newswire
The Developer's Resource & Community Site
COM XML ASP Java & Misc. NEW: VS.NET
International This Week Forums Author Central Find a Job

EJB Entity Beans

An Entity Bean represents persistent data that are maintained in a domain model, as well as methods that act on that data. Or to be more specific, an Entity Bean exactly maps to a record in your domain model. In a relational database context, there is one Bean for each row in a table. This is not a new concept, since this is how object databases have been modeled all along. A primary key identifies each Entity Bean. Entity Beans are created by using an object factory create() method. Entity beans are transactional and are recoverable following a system crash. Entity beans are also implicitly persistent. An EJB object can manage its own persistence, or it can delegate its persistence to its container.

Entity Beans always have states which can be persisted and stored across multiple invocations. Multiple EJB Clients may however share an Entity Bean. The lifetime of an Entity Bean is not limited by the lifetime of the virtual machine within which it executes. A crash of the virtual machine may result in a rollback of the current transaction, but will neither destroy the Entity Bean nor invalidate the references that other clients have to this Entity Bean. Moreover, a client can later connect to the same Entity Bean using its object reference since it encapsulates a unique primary key allowing the EJB Bean or its container to reload its state. Entity beans can thus survive system shutdowns.

Persistence in Entity Beans is of two types. They are:

Container-managed persistence: Here, the EJB container is responsible for saving the state of the Entity Bean. Since it is container-managed, the implementation is independent of the data source. However, all container-managed fields need to be specified in the Deployment Descriptor for the persistence to be automatically handled by the container.

Bean-managed persistence: Here, the Entity Bean is directly responsible for saving its own state and the container does not need to generate any database calls. Consequently, this implementation is less adaptable than the previous one as the persistence needs to be hard-coded into the Bean.

Every Entity Bean has the following characteristics:

  • Entity beans can share access from multiple users.
  • They can participate in transactions.
  • Entity beans represent data in a domain model.
  • They are persistent. They live as long as the data lives in the domain model.
  • Entity beans can survive EJB server crashes. Any EJB server crash is always transparent to the client.
  • Entity beans have a persistent object reference. The object reference encapsulates the Persistent key for this Bean.

What do you think of this article?

Have your say about the article. You can make your point about the article by mailing [email protected] (If you haven't allready joined, you can join by going to https://www.onelist.com/community/dev-java).

You can also write a review. We will publish the best ones here on this article. Send your review to [email protected]. Please include the title of the article you are reviewing.

Further Reading

The Enterprise JavaBeans Series:

Enterprise Java Beans By Gopalan Suresh Raj.
In this introduction to Enterprise Java Beans, Gopalan covers the bases then goes on to demonstrate how to build server side business object components. This article is the introduction to Gopalans series of Enterprise JavaBeans articles. (This series of articles is courtesy of Gopalan Suresh Raj)

Enterprise Java Beans Series - Components at the Server By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Model By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Naming Services and JNDI By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Transactions and JTS By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Lifecycle By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Servers By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Containers By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Components By Gopalan Suresh Raj.

Enterprise Java Beans Series - EJB Session Beans By Gopalan Suresh Raj.

Enterprise Java Beans Series - Writing an Entity Bean By Gopalan Suresh Raj.
Part 1 of a four part series: A four tier bank account example

Enterprise Java Beans Series - Writing a Session Bean By Gopalan Suresh Raj.
Part 2 of a four part series: A four tier bank account example

Enterprise Java Beans Series - Writing an EJB Client By Gopalan Suresh Raj.
Part 3 of a four part series: A four tier bank account example

Enterprise Java Beans Series - Writing an EJB Servlet Client By Gopalan Suresh Raj.
Part 4 of a four part series: A four tier bank account example


Author: Gopalan Suresh Raj

Gopalan has his own site at Author Central (visit him. He also maintains his own site at https://www.execpc.com/~gopalan/) - Contribute to iDevResource.com and you can have one too!

© Copyright 1997-2000 Gopalan Suresh Raj. Reproduced with Permission


Click here

Contribute to IDR:

To contribute an article to IDR, a click here.

To contact us at IDevResource.com, use our feedback form, or email us.

To comment on the site contact our webmaster.

Promoted by CyberSavvy UK - website promotion experts

All content © Copyright 2000 IDevResource.com, Disclaimer notice

Visit the IDR Forums

Join the Developers Webring

Learn C#

Visit the IDR Bookstore!

Code Project