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. |
- Select the project node for any EJB module project
- Choose File > New (Ctrl-N).
- Select the Entity Bean template
from the Enterprise category.
|
Generate CMP entity beans from a database. |
|
Add a finder method to an enterprise bean. |
- Open the bean class for the enterprise bean in the Source Editor.
- Right-click anywhere in the bean class and choose EJB Methods >
Add Finder Method.
|
Add a select method to an enterprise bean. |
- Open the bean class for the enterprise bean in the Source Editor.
- Right-click the bean class and choose EJB Methods > Add
Select Method.
|
Add a CMP field to an enterprise bean. |
- Open the bean class for the enterprise bean in the Source Editor.
- Right-click the bean class and choose EJB Methods > Add
CMP Field.
|
Set up container-managed relationships between entity beans. |
- Expand the Configuration Files node for the project and double-click
ejb-jar.xml.
- Click CMP Relationships
in the top of the visual editor.
- Add, edit, or remove CMP relationships in the table.
- Update any CMP mappings in the server-specific deployment descriptor.
|
Specify the database schema for an EJB module. |
- Expand the Configuration Files node for an EJB module project and
double-click sun-ejb-jar.xml.
- Select a bean in the left column and click Advanced Settings in the
Cmp Mapping tab.
- 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. |
- Double-click sun-ejb-jar.xml and select the entity bean in
the left panel.
- Make sure you have specified a database schema for the entity bean
as described above.
- In the Cmp Mapping tab, select the
primary table in the Primary Table drop-down menu.
- 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. |
- Create new entity beans in your project using the New
Entity Bean template. Do not generate CMP entity beans from a database.
- Double-click sun-ejb-jar.xml and select the Sun Configuration
node in the left panel.
- Set Create Table at Deploy to True. For more information, see Generating
Database Tables at Deployment.
|
Configure the CMP mapping for a CMP field. |
- Double-click sun-ejb-jar.xml and select the entity bean in
the left panel.
- Make sure that the database schema and primary table is specified
for the entity bean as described above.
- 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. |
- Double-click sun-ejb-jar.xml and select the entity bean in
the left panel.
- Make sure that the database schema and primary table is specified
for the entity bean as described above.
- In the Cmp Mapping tab, select <map
multiple columns> in the Mapped Column column for the field.
|
Map a container-managed relationship field. |
- Make sure you have configured
the container-managed relationship in the general deployment descriptor.
- Double-click sun-ejb-jar.xml and select an entity bean in
the left panel.
- In the Cmp Mapping tab, select
<map relationship field> in the Mapped Column column
for the field.
|