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:

  1. Open the bean class in the Source Editor.
  2. Right-click anywhere in the Source Editor and choose Insert Code > Add Select Method.
  3. In the Add Select Method dialog box, define the method signature:
    1. Add text to the base ejbSelectBy name of the method.
    2. 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.
    3. Enter the EJB QL statement that the method will use to find the data that it is to return.
    4. Specify any parameters that the method needs.
  4. 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:

  1. In the Projects window, expand the Configuration Files node for your EJB module project.
  2. Double-click ejb-jar.xml. The graphical editor opens in the Details view.
  3. Click the XML tab and make your changes in the XML editor.
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