BMP Entity Bean Sample

The Bean-Managed Persistence (BMP) entity bean sample shows how to build a basic entity bean using bean-managed persistence instead of container managed persistence. This example is intended to provide a comparison between how a BMP entity bean and a CMP entity bean implement similar behavior, and to that effect implements the BMPItemBean entity bean, which is similar to the CMP entity bean ItemsBean_F in the Finder Methods Sample. The entity bean implements several persistence fields and their accessor methods, an ejbCreate method, a finder method ejbFindByPrice, and the methods that you need to explicitly define in BMP to handle database queries, that is, findByPrimaryKey, ejbLoad, ejbStore, ejbRemove, as well as setEntityContext and unsetEntityContext. The example uses JDBC to talk to a relational database.

Concepts Demonstrated by this Sample

Location of Sample Files

The code of the BMP entity bean is located in the beanManagedPersistence folder of the EJBs project in the SamplesApp sample application. In the file system the location is:

BEA_HOME\weblogic81\samples\workshop\SamplesApp\EJBs\beanManagedPersistence

The web service that you run as a client application to test the EJB, and the EJB control that you use to locate and reference the EJB, are located in the beanManagedPersistence folder of the EJBs_ClientApps project in the SamplesApp sample application. In the file system the location is:

BEA_HOME\weblogic81\samples\workshop\SamplesApp\EJBs_ClientApps\beanManagedPersistence

To Run the Sample

  1. Start WebLogic Server in the appropriate domain.
  1. Launch the BMPItemBeanCtrlTest web service either by opening it in WebLogic Workshop and selecting the Start operation or by entering http://localhost:7001/EJBs_ClientApps/beanManagedPersistence/BMPItemBeanCtrlTest.jws in the address bar of your browser. If WebLogic Server is running in the appropriate domain on this machine, you may click here to run the sample.
  2. Navigate to the Test Form tab of Test View, if necessary.
  3. Invoke the startTestDrive method to create a new conversational instance.
  4. Click continue this conversation.
  5. Locate the create method, provide a unique number, name, and price, and click the create button.
  6. Click continue this conversation.
  7. Repeat the last two steps a number of times to enter additional items to the database.
  8. Locate the findByPrimaryKey method, enter the number of a previously entered product, and click the findByPrimaryKey button.
  9. Click continue this conversation.
  10. Use any of the getter methods to verify that the correct product has been returned.
  11. Click continue this conversation.
  12. Locate the findByPrice method, enter a price, and click the findByPrimaryKey button. Click continue this conversation, and examine the returned set of items.
  13. Return to WebLogic Workshop and press the Stop button to close the Test Browser.

Related Topics

Bean-Managed Persistence