Creating entity beans with bean-managed persistence (BMP)
You can use the Create an Enterprise Bean wizard to create an entity bean that will manage its own persistence.
To create an enterprise bean, first have an EJB project defined.
As opposed to entity beans with container-managed persistence (CMPs), where the code for persisting serializable data is included in the container, entity beans with bean-managed persistence include the code for any persistence mechanism. For example, any JDBC code that you require to manage persistence needs to be manually coded in the entity bean class or in helper classes.
A BMP entity bean can also be used where data exists in an application rather than a database. In other words, if the data source is not supported by CMP entity beans, it is likely that a BMP would be an appropriate alternative, which would allow you to use non-JDBC databases and stored procedures.
To create an entity bean with bean-managed persistence (BMP):
- In the J2EE perspective, click File > New > Enterprise Bean. The Create an Enterprise Bean wizard appears.
- Select the Entity bean with bean-managed persistence (BMP) fields radio button.
- Select the EJB project that you want to add the bean to.
- In the Bean name field, type the name that you want to assign to the enterprise bean. By convention, bean names should begin with an uppercase letter.
Note: You can use Unicode characters for the bean name, but Unicode characters are not supported for enterprise bean packages and classes associated with enterprise beans.
- In the Source folder field, select the source folder for the new bean.
- In the Default package field, enter the package name for the new bean.
- Optional: For EJB 2.x beans, you can select Generated an annotated bean class. If you select this option, the wizard generates annotations at the beginning of the Java code for the bean class. The annotations define the bean's implementation as you specify in the wizard. The annotations are then used by the EJB tools to generate the necessary bean classes, and to provide values that are inserted in the EJB deployment descriptor (ejb-jar.xml). Select this option if you are familiar with annotations and want to use the annotations to update the bean rather than using the deployment descriptor.
For more information, see Annotation-based programming overview.
- Click Next.
- If you want the new bean to inherit from an existing bean of the same type in the same EJB project, select a bean in the Bean supertype drop-down list.
- In the Bean class field, enter the desired package and class name for the bean class. By default, the wizard suggests a bean class based on the bean name and default package that you defined. A bean class can be a new class that the wizard generates, or it can be an existing class in the project class path. Click the Class button to open a dialog that lists the classes in the project that correspond to the bean type. The name of the bean class appears blue for existing classes with source. The name of the bean class appears red for existing binary classes.
- Define the client views and interfaces. For EJB 2.0 or later beans, you can include a remote client view, a local client view, or both. For EJB 1.1 beans, only a remote client view is supported. Every session or entity bean must have at least one client view:
- Remote client view: Select this check box to include a remote client view for the session bean.
In the Remote home interface and Remote interface fields, enter the package and class names that you want to use for the remote client view interfaces. The wizard uses the bean name and default package to suggest values for the interface package and class names.
- Local client view: Select this check box to include a local client view for the session bean.
In the Local home interface and Local interface fields, enter the package and class names that you want to use for the local client view interfaces. The wizard uses the bean name and default package to suggest values for the interface package and class names.
- In the Key class field, enter the desired package name and class for the entity bean's key class. By default, the wizard suggests a class name and package based on the bean name and default package that you defined. A bean class can be a new class that the wizard generates, or it can be an existing class in the project class path. Click the Class button to open a dialog that lists the classes in the project that correspond to the bean type. The name of the bean class appears blue for existing classes with source. The name of the bean class appears red for existing binary classes.
- Click Next.
- Optional: In the Bean superclass field, type or select the desired class. This field is disabled if a bean supertype was specified.
- Optional: Define any interfaces that you want the remote or local client interfaces to extend:
- Click the Add button to open the Type Selection dialog box where you can select the interface that you want to extend.
- If you added an interface that you no longer want to extend, select the interface in the list and click Remove.
- Click Finish. The new entity bean is added to the specified EJB project.
Parent topic
Creating enterprise beans