Java Reference
In-Depth Information
n Note If you would like to execute HQL statements through a GUI-based tool, the Hibernate team provides
a Hibernate console for Eclipse in the Hibernate Tools subproject. This console is a plug-in for recent ver-
sions of Eclipse. This tool is described in detail in Appendix B.
Syntax Basics
HQL is inspired by SQL and is the inspiration for the new EJB Query Language (EJB QL). The
EJB QL specification is included in the standard for EJB 3 available from the Java Community
Process web site ( www.jcp.org/en/jsr/detail?id=220 ). HQL's syntax is defined as an ANTLR
grammar; the grammar files are included in the grammar directory of the Hibernate core down-
load (ANTLR is a tool for building language parsers).
As the ANTLR grammar files are somewhat cryptic, and as not every statement that is per-
missible according to the ANTLR grammar's rules can be used in Hibernate, we outline the
syntax for the four fundamental HQL operations in this section. Note that the following descrip-
tions of syntax are not comprehensive—there are some deprecated or more obscure usages
(particularly for SELECT statements) that are not covered here.
UPDATE
UPDATE alters the details of existing objects in the database. In-memory entities will not be
updated to reflect changes resulting from issuing UPDATE statements. Here's the syntax of the
UPDATE statement:
UPDATE [VERSIONED]
[FROM] path [[AS] alias] [, ...]
SET property = value [, ...]
[WHERE logicalExpression]
path is the fully qualified name of the entity or entities. The alias names may be used to
abbreviate references to specific entities or their properties, and must be used when property
names used in the query would otherwise be ambiguous.
The property names are the names of properties of entities listed in the FROM path.
The syntax of logical expressions is discussed later, in the “Using Restrictions with HQL”
section.
DELETE
DELETE removes the details of existing objects from the database. In-memory entities will not
be updated to reflect changes resulting from DELETE statements. This also means that cascade
rules will not be followed for deletions carried out using HQL. This approach to deletion is
commonly referred to as “bulk deletion” since it is the most efficient way to remove large
numbers of entities from the database. Here's the syntax of the DELETE statement:
Search WWH ::




Custom Search