Java Persistence Query Language
Encyclopedia
The Java Persistence Query Language (JPQL) is a platform-independent object-oriented query language
defined as part of the Java Persistence API
specification.
JPQL is used to make queries against entities stored in a relational database. It is heavily inspired by SQL
, and its queries resemble SQL queries in syntax, but operate against JPA entity objects rather than directly with database tables.
In addition to retrieving objects (
Then a simple query to retrieve the list of all authors, ordered alphabetically, would be:
To retrieve the list of authors that have ever been published by XYZ Press:
JPQL supports named parameters, which begin with the colon (
object-relational mapping
library.
Hibernate and the HQL were created before the JPA specification.
As of Hibernate 3 JPQL is a subset of HQL.
Query language
Query languages are computer languages used to make queries into databases and information systems.Broadly, query languages can be classified according to whether they are database query languages or information retrieval query languages...
defined as part of the Java Persistence API
Java Persistence API
The Java Persistence API, sometimes referred to as JPA, is a Java programming language framework managing relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition....
specification.
JPQL is used to make queries against entities stored in a relational database. It is heavily inspired by SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....
, and its queries resemble SQL queries in syntax, but operate against JPA entity objects rather than directly with database tables.
In addition to retrieving objects (
SELECT
queries), JPQL supports set based UPDATE
and DELETE
queries.Examples
Suppose we have JPA entity classes defined like this (getter and setter methods omitted for simplicity):Then a simple query to retrieve the list of all authors, ordered alphabetically, would be:
To retrieve the list of authors that have ever been published by XYZ Press:
JPQL supports named parameters, which begin with the colon (
:
). We could write a function returning a list of authors with the given last name as follows:Hibernate Query Language
JPQL is based on the Hibernate Query Language (HQL), an earlier non-standard query language included in the HibernateHibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...
object-relational mapping
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...
library.
Hibernate and the HQL were created before the JPA specification.
As of Hibernate 3 JPQL is a subset of HQL.