EJB 2.1 Entity Beans: Quick Reference

This topic describes common tasks you can perform with EJB 2.1 entity beans. For more detailed information, click the links in the right column.

To perform this task Follow these steps
Create an entity bean.
  1. Select the project node for any EJB module project
  2. Choose File > New (Ctrl-N).
  3. Select the Entity Bean template from the Enterprise category.
Generate CMP entity beans from a database.
Add a finder method to an enterprise bean.
  1. Open the bean class for the enterprise bean in the Source Editor.
  2. Right-click anywhere in the bean class and choose EJB Methods > Add Finder Method.
Add a select method to an enterprise bean.
  1. Open the bean class for the enterprise bean in the Source Editor.
  2. Right-click the bean class and choose EJB Methods > Add Select Method.
Add a CMP field to an enterprise bean.
  1. Open the bean class for the enterprise bean in the Source Editor.
  2. Right-click the bean class and choose EJB Methods > Add CMP Field.
Set up container-managed relationships between entity beans.
  1. Expand the Configuration Files node for the project and double-click ejb-jar.xml.
  2. Click CMP Relationships in the top of the visual editor.
  3. Add, edit, or remove CMP relationships in the table.
  4. Update any CMP mappings in the server-specific deployment descriptor.
Specify the database schema for an EJB module.
  1. Expand the Configuration Files node for an EJB module project and double-click sun-ejb-jar.xml.
  2. Select a bean in the left column and click Advanced Settings in the Cmp Mapping tab.
  3. Select the database schema in the Database Schema drop-down menu. The list contains all of the .dbschema files in your project's src/conf folder.
Specify the primary and secondary tables for an entity bean.
  1. Double-click sun-ejb-jar.xml and select the entity bean in the left panel.
  2. Make sure you have specified a database schema for the entity bean as described above.
  3. In the Cmp Mapping tab, select the primary table in the Primary Table drop-down menu.
  4. Click Advanced Settings and specify any secondary tables in the Advanced Settings dialog box.
Set the EJB module to generate database tables when the module is deployed.
  1. Create new entity beans in your project using the New Entity Bean template. Do not generate CMP entity beans from a database.
  2. Double-click sun-ejb-jar.xml and select the Sun Configuration node in the left panel.
  3. Set Create Table at Deploy to True. For more information, see Generating Database Tables at Deployment.
Configure the CMP mapping for a CMP field.
  1. Double-click sun-ejb-jar.xml and select the entity bean in the left panel.
  2. Make sure that the database schema and primary table is specified for the entity bean as described above.
  3. In the Cmp Mapping tab, specify the mapping for each field in the Mapped Column column of the table.
Map a CMP field to multiple database columns.
  1. Double-click sun-ejb-jar.xml and select the entity bean in the left panel.
  2. Make sure that the database schema and primary table is specified for the entity bean as described above.
  3. In the Cmp Mapping tab, select <map multiple columns> in the Mapped Column column for the field.
Map a container-managed relationship field.
  1. Make sure you have configured the container-managed relationship in the general deployment descriptor.
  2. Double-click sun-ejb-jar.xml and select an entity bean in the left panel.
  3. In the Cmp Mapping tab, select <map relationship field> in the Mapped Column column for the field.

Legal Notices