What is EJB QL?

malay thakkar

EJB QL is a Query Language provided for navigation across a network of enterprise beans and dependent objects defined by means of container managed persistence. EJB QL is introduced in the EJB 2.0 specification. The EJB QL query language defines finder methods for entity beans with container managed persistenceand is portable across containers and persistence managers. EJB QL is used for queries of two types of finder methods:

  1. Finder methods that are defined in the home interface of an entity bean and which return entity objects.
  2. Select methods, which are not exposed to the client, but which are used by the Bean Provider to select persistent values that are maintained by the Persistence Manager or to select entity objects that are related to the entity bean on which the query is defined.

From the EJB 2.0 spec:

The Enterprise JavaBeans query language, EJB QL, is used to define finder queries for entity beans with container managed persistence. EJB QL lets the Bean Provider specify finder methods in a portable way. It is a specification language that can be compiled to a target language, such as SQL, of a persistent store used by a persistence manager. This allows the responsibility for the execution of finder queries to be shifted to the native language facilities provided for the persistent store (e.g., RDBMS), instead of requiring finder queries to be executed directly on the persistent manager’s representation of the entity beans’ state. As a result, finder methods are both portable and optimizable.