C M P 2 . 0
ejbSelectBoss
java.lang.String
SELECT DISTINCT underling.organization.theBoss
FROM gangster underling
WHERE underling.name = ?1 OR underling.nickName = ?1
]]>
Listing 9 14, The ejb jar.xml Query Declaration
EJB QL is similar to SQL but has some surprising differences. The following are some
important things to note about EJB QL:
EJB QL is a typed language, meaning that it only allows comparison of like types
(i.e., strings can only be compared with strings).
In an equals comparison a variable (single valued path) must be on the left hand side.
Some examples follow:
7
g.hangout.state = CA
Legal
CA = g.shippingAddress.state
NOT Legal
CA = CA
NOT Legal
(r.amountPaid * .01) > 300
NOT Legal
r.amountPaid > (300 / .01)
Legal
Parameters use a base 1 index like java.sql.PreparedStatement.
Parameters are only allowed on the right hand side of a comparison. For example:
gangster.hangout.state = ?1
Legal
?1 = gangster.hangout.state
NOT Legal
Datetime variables (simgle valued paths) are only allowed to use the > and <
operators and EJB QL does not have datetime literals. For example:
someEntity.datetimeField > ?1
Legal
someEntity.datetimeField >= ?1
NOT Legal
someEntity.datetimeField BETWEEN ?1 AND ?2
NOT Legal
someEntity.datetimeField > ?1 AND someEntity.datetimeField < ?2
Legal
7
The example "(r.amountPaid * .01) > 300" is presented on page 244 of "Enterprise JavaBeans 3
rd
Edition" by Richard Monson Haefel to
demonstrate the use of arithmetic operators in a WHERE clause, and is included here to highlight the fact that it is not legal EJB QL syntax.
96
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved