An entity bean represents persistent data in a database, as well as methods that act on that data. In a relational database context, one bean exists for each row in a table (although an entity might be based on a view or some other complex query as well). A unique primary key identifies each entity bean to a record. When you create an entity bean with the EJB Wizard, it creates an entity bean by using a create() method, as well as its primary key.
In general, the life cycle of an entity bean is not limited by the life cycle of the virtual machine in which it executes. If the virtual machine crashes, or the database rolls back the current transaction, the entity bean and its references from other clients are not destroyed. Later, a client can reconnect to the same entity bean using its object reference and primary key or when its container reloads its state.
An entity bean can manage its own persistence (bean-managed persistence, or BMP) or have its container manage it (container-managed persistence, or CMP).
A container-managed persistence (CMP) entity bean delegates its persistence tasks to its container, which frees you to develop the business logic for your EJB. When you deploy your entity bean with JDeveloper, JDeveloper identifies the CMP fields in the deployment descriptor and how they are mapped to the database. The container generates the necessary logic to persist the entity bean.
Fields that are mapped to the database are called container-managed fields. These fields can be any Java primitive type or serializable object which you can create and manage through the EJB Module Editor.
You can reverse-engineer CMP beans from a database table using the JDeveloper modeling tools and/or wizards. You can also create EJBs in JDeveloper and then generate them as database tables.
A bean-managed persistence (BMP) bean requires that you explicitly write the persistence logic for it. In addition to knowing database technology, you'll need to explicitly map the bean's fields to the data source.
BMP beans can be mapped to multiple databases at the same time, or legacy systems, such as a flat file for example. Unless you are working with outside cases like this, CMP beans are recommended; they are easier to use and provide a a better forward migration path.
Developing Enterprise JavaBeans
Copyright © 1997, 2004, Oracle. All rights reserved.