Sun Java System Application Server Platform Edition 8.1 2005Q2 Update 2 Upgrade and Migration Guide

Custom Finder Methods

The custom finder methods are the findBy... methods (other than the default findByPrimaryKey method), which can be defined in the home interface of an entity bean. Since the EJB 1.1 specification does not stipulate a standard for defining the logic of these finder methods, EJB server vendors are free to choose their implementations. As a result, the procedures used to define the methods vary considerably between the different implementations chosen by vendors.

Sun ONE Application Server 6.x uses standard SQL to specify the finder logic.

Information concerning the definition of this finder method is stored in the enterprise bean’s persistence descriptor (Account-ias-cmp.xml) as follows:

<bean-property>
  <property>
    <name>findOrderedAccountsForCustomerSQL</name>
    <type>java.lang.String</type>
    <value>
       SELECT BRANCH_CODE,ACC_NO FROM ACCOUNT where CUST_NO = ?
    </value>
    <delimiter>,</delimiter>
  </property>
</bean-property>
<bean-property>
  <property>
    <name>findOrderedAccountsForCustomerParms</name>
    <type>java.lang.Vector</type>
    <value>CustNo</value>
    <delimiter>,</delimiter>
  </property>
</bean-property>

Each findXXX finder method therefore has two corresponding entries in the deployment descriptor (SQL code for the query, and the associated parameters).

In Sun Java System Application Server 8.1 the custom finder method logic is also declarative, but is based on the EJB query language EJB QL.

The EJB-QL language cannot be used on its own. It has to be specified inside the file ejb-jar.xml, in the <ejb-ql> tag. This tag is inside the <query> tag, which defines a query (finder or select method) inside an EJB. The EJB container can transform each query into the implementation of the finder or select method. Here’s an example of an <ejb-ql> tag:

<ejb-jar>   
  <enterprise-beans>     
    <entity>
      <ejb-name>hotelEJB</ejb-name>       
      ...       
      <abstract-schema-name>TMBankSchemaName</abstract-schema-name>       
      <cmp-field>
      ...       
      <query>         
        <query-method>           
          <method-name>findByCity</method-name> 
            <method-params>             
              <method-param>java.lang.String</method-param> 
            </method-params>         
        </query-method>         
        <ejb-ql>           
          <![CDATA[SELECT OBJECT(t) FROM TMBankSchemaName AS t 
                                         WHERE t.city = ?1]]>
        </ejb-ql>       
      </query>     
    </entity>   
    ...   
  </enterprise-beans> ... 
</ejb-jar>