Chapter 27. Exercises for Chapter 9

Exercise 9.1: A BMP Entity Bean

In this exercise, you will build and examine a simple EJB that uses bean-managed persistence (BMP) to synchronize the state of the bean with a database. You will also build a client application to test this Ship BMP bean.

Start Up JBoss

If JBoss is already running, there is no reason to restart it.

Initialize the Database

As in the CMP examples, the state of the entity beans will be stored in the database that is embedded in JBoss. JBoss was able to create all tables for CMP beans, but it cannot do the same for BMP beans because the deployment descriptors don’t contain any persistence information (object-to-relational mapping, for example). The bean is in fact the only one that knows how to load, store, remove, and find data. The persistence mapping is not described in a configuration file, but embedded in the bean code instead.

One consequence is that the database environment for BMP must always be built explicitly. To make this task easier for the BMP Ship example, Ship’s home interface defines two helpful home methods.

Tip

Entity beans can define home methods that perform operations related to the EJB component’s semantics but that are not linked to any particular bean instance. As an analogy, consider the static methods of a class: their semantics are generally closely related to the class’s semantics, but they’re not associated with any particular class instance. Don’t worry if this is not totally clear: Chapter ...

Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.