Create EJB queries using EJB Query Language

The EJB query language is a query specification language, similar to SQL, for entity beans with container-managed persistence. With it, the Bean Provider is able to specify the semantics of custom finder or EJB select methods in a portable way and in terms of the object model's entities, instead of the relational model's entities. This is possible because EJB QL is based on the abstract schema types of the entity beans.

Note: Both finder and EJB select methods are used to query the backend where the actual data is stored. The difference is that finder methods are accessible to the entity beans' clients, whereas select methods are internal to the implementation and not visible to clients.

An EJB QL query is a string consisting of the following clauses:

EJB QL queries are defined by the Bean Provider in the deployment descriptor. The SQL statements for the actual database access is generated automatically by the deployment tooling. As an example, this query retrieves customers that have accounts with a large balance:

SELECT OBJECT(c) FROM Customer c, IN(c.accounts) a WHERE a.balance > ?1
					

As you can see, this EJB QL statement is independent of the database implementation. It follows a CMR relationship from customer to account and queries the account balance. Finder and EJB select methods specified using EJB QL are portable to any EJB 2.1 environment.

Note: These finder and EJB select methods may also be portable to EJB 2.0 environments if they do not use the new order and aggregate features defined by the EJB 2.1 specification.

Finder and Select Methods

Finder and select methods use EJB QL queries to return objects and state information of entity beans using container-managed persistence.

A select method is similar to a finder method in the following ways:

However, a select method differs significantly from a finder method:

The signature for a select method must follow these rules:

BOOT.BY - Tech Industry News         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free SCBCD 5.0 Study Guide