EJB query language
EJB query language enables you to write queries based on entity beans without knowing the underlying relational schema.
An EJB query is a string containing the following elements:
- a SELECT clause that specifies the enterprise beans or values to return;
- a FROM clause that names the bean collections;
- an optional WHERE clause containing search predicates over the collections;
- an optional GROUP BY and HAVING clause; see the topic Aggregation functions.
- an optional ORDER BY clause that specifies the ordering of the result collection.
Collections of entity beans are identified in EJB queries through the use of their abstract schema name in the query FROM clause.
The elements of EJB query language are discussed in more detail in the following related topics.
Subtopics
- FROM clause
The FROM clause specifies the collections of objects to which the query is to be applied. Each collection is specified either by an abstract schema name (ASN) or by a path expression identifying a relationship. An identification variable is defined for each collection.
- Inheritance in EJB query
If an EJB inheritance hierarchy has been defined for an abstract schema, using the abstract schema name in a query statement implies the collection of objects for that abstract schema as well as all subtypes.
- Path expressions
A path expression is an identification variable followed by the navigation operator ( . ) and a container managed persistence (CMP) or relationship name.
- WHERE clause
The WHERE clause lists search conditions for items to add to a result set.
- Scalar functions
An EJB query contains scalar functions for doing type conversions, string manipulation, and for manipulating date-time values.
- Aggregation functions
Aggregation functions operate on a set of values to return a single scalar value. We can use these functions in the select and subselect methods.
- SELECT clause
The SELECT clause consists of either a single identification variable defined in the FROM clause, or a single valued path expression that evaluates to an object reference or container managed persistence (CMP) value. We can use the DISTINCT keyword to eliminate duplicate references.
- ORDER BY clause
The ORDER BY clause specifies an ordering of the objects in the result collection
- UNION clause operation
The UNION clause specifies a combination of the output of two subqueries. The two queries must return the same number of elements and compatible types.
- Subqueries
A subquery can be used in quantified predicates, the EXISTS predicate, or the IN predicate. A subquery should only specify a single element in the SELECT clause.
- EJB query language limitations and restrictions
When using the EJB query language on the product, deviations can be seen in comparison to standard EJB query language. The limitations and restrictions you must be aware of are listed in the following section.
- EJB query compatibility issues with SQL
Because an EJB query is compiled into SQL, you must be aware of compatibility issues between the Java language and SQL.
- Database restrictions for EJB query
The EJB query functions must adhere to certain restrictions for databases.
- Rules for data type manipulation in EJB query
When using an EJB query to work with data types, certain rules must be followed.
- EJB query: Reserved words
The following words are reserved in WebSphere Application Server EJB queries.
- EJB query: BNF syntax
The Backus-Naur Form (BNF) is one of the most commonly used notations for specifying the syntax of programming languages or command sets. This article lists the syntax for Enterprise JavaBeans (EJB) query language.
- EJB specification and WebSphere query language comparison
WebSphere Application Server extends the Enterprise JavaBeans (EJB) query language with elements of its own.
Related tasks
Use EJB query