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 Insert Code > 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 Insert Code > 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 Insert Code > Add CMP Field.
Modify 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. Double-click the relationship name in the table to edit the relationship or select the name and click Remove to remove the relationship.
  4. Update any CMP mappings in the server-specific deployment descriptor.
  5. Update your source code where necessary.
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. Click the XML tab to open the file in the XML editor.
  3. Edit the XML to specify the schema properties. You can use the IDE's XML code completion to help you edit the XML.
  4. Validate your XML and save the file.
Specify the primary and secondary tables for an entity bean.
  1. Expand the Configuration Files node for an EJB module project and double-click sun-cmp-mappings.xml.
  2. Make sure you have specified a database schema for the entity bean as described above.
  3. Edit the XML to specify the table properties. You can use the IDE's XML code completion to help you edit the XML.
  4. Validate your XML and save the file.
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. Expand the Configuration Files node for an EJB module project and double-click sun-ejb-jar.xml.
  3. Click the XML tab to open the file in the XML editor.
  4. Edit the XML to set the create-tables-at-deploy to True. You can use the IDE's XML code completion to help you edit the XML. For more information, see Generating Database Tables at Deployment.
  5. Validate your XML and save the file.
Configure the mappings for CMP fields or CMR fields.
  1. Make sure that the data source and primary table are specified for the entity bean as described above.
  2. Expand the Configuration Files node for an EJB module project and double-click sun-cmp-mappings.xml.
  3. Edit the XML to map the CMP fields and CMR fields. You can use the IDE's XML code completion to help you edit the XML. For more information, see Configuring CMP Mappings.
  4. Validate your XML and save the file.
  5. Update your source code where necessary.

Legal Notices