Presented by developerWorks, your source for great tutorials
ibm.com/developerWorks
Section 9. Example 2: Finder methods and EJB QL
Finder methods and EJB QL
The Enterprise JavaBeans Query Language (EJB QL), a subset of SQL92, allows the
definition of finder methods in the deployment descriptor for entity beans with
container managed persistence. EJB QL is a powerful little language that is easy to
learn and use. Like SQL, EJB QL is easy to learn, but takes some time to master.
EJB QL was extended to navigate over CMR relationships. The EJB container is
responsible for translating EJB QL queries into the query language of the persistent
datastore, for example, SQL 92 for IBM DB2. This translation results in creating finder
methods that are more portable. This allows enterprise component vendors to sell
components that work on more target platforms. The third tutorial in this series will
cover EJB QL in detail. Here is a small taste.
Creating a
findAll()
method for
UserBean
Finder methods allow entities to be found based on a criteria. Finder methods are
defined in the home interface. Prior to EJB 2.0 it was up to the developer to create his
own finder methods (or a propietary EJB vendor solution). The developer would
declare a finder method in the home interface let s say
findAll()
then the developer
would define the corresponding definition of the finder method in the bean
implementation for example
ejbFindAll()
.
Listing 11: Home interface for
findAll()
/** Home interface now has findAll method **/
package com.rickhightower.auth;
import java.util.Collection;
public interface LocalUserHome extends EJBLocalHome {
public Collection findAll() throws FinderException;
}
With EJB 2.0 CMP, you merely define the finder method definition in the deployment
descriptor using EJB QL. You still have to declare the finder method in the home
interface. Note that the finder method
public Collection findAll() throws
FinderException
is declared in the home.
Introducing EJB CMP/CMR, Part 1 of 2
Page 43 of 48






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

tomcat web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved