Defining a Select Method
See Also
Select methods are a type of query method that, like finder methods, is used
in EJB 2.1 CMP entity beans to query databases. A select method is more flexible than a finder
method and is visible only to the bean class; therefore, a select method can be used only
by methods of the bean class. A select method inherits the transaction context
of the method that calls it. In addition to returning a bean or a collection
of beans, a select method can also return the value of a field. Select methods are
only available for entity beans that use container-managed persistence (CMP).
To define a select method for a CMP entity bean:
- Open the bean class in the Source Editor.
- Right-click anywhere in the Source Editor and choose Insert Code > Add
Select Method.
- In the Add Select Method dialog box, define the method signature:
- Add text to the base ejbSelectBy name of the method.
- Choose the method's return type from the combo box:
- If the method returns the value of a CMP field, choose the appropriate
Java or primitive data type, such as java.lang.String or
int.
- If the method returns an enterprise bean, type the bean's type in
the combo box.
- If the method returns more than one bean, type java.util.Set
or java.util.Collection in the combo box. Use java.util.Set
if the returned beans cannot be duplicates. Use java.util.Collection
if the returned beans can be duplicates.
- Enter the EJB QL statement that the method will use to find the data
that it is to return.
- Specify any parameters that the method needs.
- Click OK to create the method.
The IDE adds the method signature to the bean class and registers the
select method to the EJB module's deployment descriptor.
To view or edit an existing select method:
- In the Projects window, expand the Configuration Files node for your EJB
module project.
- Double-click ejb-jar.xml. The graphical editor opens in the Details
view.
- Click the XML tab and make your changes in the XML editor.
- If you make changes to ejb-jar.xml you will
also need to make corresponding changes in your bean source code.
- See Also
- About Entity Beans
- Defining a Finder Method
- Defining a Business Method
- Adding EJB QL to a Finder or Select Method
- About EJB 2.1 CMP Mappings
- Defining a CMP Field
- Generating CMP Entity Beans from a Database
Legal Notices