The Query Methods
There are two main types of query methods: find methods and select methods. These are discussed in the following sections.
Find Methods
Find methods are invoked by EJB clients (applications or beans) to
obtain EJB object references to specific entity beans. For example,
you might call the findByPrimaryKey( )
method on the Customer
EJB’s home interface to obtain a reference to a
specific Customer bean.
Find methods are always declared in the
local and remote home interfaces of an entity bean. Specifying a
single remote or local return type for a find method indicates that
the method locates only one bean. findByPrimaryKey( )
obviously returns a single remote reference, because
there is a one-to-one correspondence between a primary
key’s value and an entity. Other single-entity find
methods can also be declared. For example, in the following code
segment the Customer EJB declares several single-entity find methods,
each of which supports a different query:
public interface CustomerHomeRemote extends javax.ejb.EJBHome { public CustomerRemotefindByPrimaryKey
(Integer primaryKey) throws javax.ejb.FinderException, java.rmi.RemoteException; public CustomerRemotefindByName
(String lastName, String firstName) throws javax.ejb.FinderException, java.rmi.RemoteException; public CustomerRemotefindBySSN
(String socialSecurityNumber) throws javax.ejb.FinderException, java.rmi.RemoteException; }
Bean developers can also define multi-entity find methods, which return a collection ...
Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.