EJB Query Language
The Enterprise JavaBeans Query Language ("EJB QL") defines the queries for the finder and select methods of an entity bean with container-managed persistence.
Features:
1. EJB QL is a subset of SQL92
2. You define EJB QL queries in the deployment descriptor of the entity bean.
Typically, a tool will translate these queries into the target language of the
underlying data store. Because of this translation, entity beans with
container-managed persistence are portable--their code is not tied to a specific
type of data store.
กก
Examples:
EJB QL statements are declared in the entity bean's deployment descriptor. The home interface of the
Employee
bean may be declared as follows:
public interface EmployeeHome extends
javax.ejb.EJBHome {
...
public Employee findByPrimaryKey(Integer id)
throws RemoteException, CreateException;
public Collection findByZipCode(String zipcode)
throws RemoteException, CreateException;
}
กก
The
findByZipCode()
method is used to obtain all the
Employee
beans with a certain zip code. That would be expressed by using the following
EJB QL in the deployment descriptor.
FROM contactInfo WHERE contactInfo.zip = ?1
This statement basically says "select all the
Employee
beans that have a zip code equal to the
zipcode
argument." The
SELECT
clause, which indicates what to select, is not needed in the EJB QL statements
for find methods. That is because the find methods will always select the remote
references of its own bean type. In that case, the select statement is supposed
to return a collection of remote
Employee
bean references.