Java Persistence Query Language
   HOME

TheInfoList



OR:

The Jakarta Persistence Query Language (JPQL; formerly Java Persistence Query Language) is a platform-independent
object-oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of '' objects''. Objects can contain data (called fields, attributes or properties) and have actions they can perform (called procedures or methods and impleme ...
query language A query language, also known as data query language or database query language (DQL), is a computer language used to make queries in databases and information systems. In database systems, query languages rely on strict theory to retrieve informa ...
defined as part of the Jakarta Persistence (JPA; formerly Java Persistence API) specification. JPQL is used to make queries against entities stored in a relational database. It is heavily inspired by
SQL Structured Query Language (SQL) (pronounced ''S-Q-L''; or alternatively as "sequel") is a domain-specific language used to manage data, especially in a relational database management system (RDBMS). It is particularly useful in handling s ...
, 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

Example JPA Classes, getters and setters omitted for simplicity. @Entity public class Author @Entity public class Book @Entity public class Publisher Then a simple query to retrieve the list of all authors, ordered alphabetically, would be: SELECT a FROM Author a ORDER BY a.firstName, a.lastName To retrieve the list of authors that have ever been published by XYZ Press: SELECT DISTINCT a FROM Author a INNER JOIN a.books b WHERE b.publisher.name = '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: import javax.persistence.EntityManager; import javax.persistence.TypedQuery; ... public List getAuthorsByLastName(String lastName)


Hibernate Query Language

JPQL is based on the Hibernate Query Language (HQL), an earlier non-standard query language included in the
Hibernate Hibernation is a state of minimal activity and metabolic reduction entered by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It is most ...
object-relational mapping library. Hibernate and the HQL were created before the JPA specification. As of Hibernate 3 JPQL is a subset of HQL.


Citations


References

*


See also

* Object-relational mapping *
Hibernate (framework) Hibernate ORM (or simply Hibernate) is an object–relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database. Hibernate handles object–relational ...
* Jakarta Persistence


External links

* *
Full Query Language Syntax from The Jakarta EE 8 Tutorial

JPA Queries and JPQL - a chapter of the ObjectDB Manual

Type safe Hibernate (HQL) query engine - TorpedoQuery
{{Jakarta Persistence Query languages Data modeling languages Java enterprise platform