Skip Headers

# EJB QL Queries

Previous

Next

Like SQL, EJB QL is a query language; but unlike SQL, it presents queries from an object model perspective, allowing you to declare queries using the attributes of each abstract entity bean in your object model. It also includes path expressions that enable navigation over the relationships defined between entity beans and dependent objects.

Using EJB QL offers the following advantages:

- You do not need to know the database structure (such as tables and fields).

- You can construct queries using the attributes of the entity beans instead of using database tables and fields.

- You can use relationships in a query to provide navigation from attribute to attribute.

- EJB QL queries are portable because they are database-independent.

- You can specify the reference class in the `SELECT` clause.

The disadvantage of EJB QL queries is that it is difficult to use when you construct complex queries.

TopLink provides the full support for the EJB QL specification.

Note: TopLink supports the `LOCATE` string function and will generate the correct SQL with it. However, not all data sources support `LOCATE`. Before using the `LOCATE` string function, consult your data source documentation.

EJB QL is the standard query language first defined in the EJB 2.0 specification. Consequently, TopLink lets you specify selection criteria using EJB QL in an EJB finder (see "EJB QL Finders").

Although EJB QL is usually associated with EJB, TopLink also lets you specify selection criteria using EJB QL in queries for regular Java objects as well. TopLink provides an EJB QL `Call` that you can execute directly or in the context of a `DatabaseQuery`. For more information, see "EJB QL Calls" and "DatabaseQuery".