Java Persistence Query Language
Java Persistence Query Language
Influenced by
SQL, Hibernate

The Java Persistence Query Language (JPQL) is a platform-independent object-oriented query language defined as part of the Java Persistence API (JPA) 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 (SELECT queries), JPQL supports set based UPDATE and DELETE queries.


Example JPA Classes, getters and setters omitted for simplicity.

public class Author {
    private Integer id;
    private String firstName;
    private String lastName;
    private List<Book> books;
public class Book {
    private Integer id;
    private String title;
    private String isbn;
    private Publisher publisher;
    private List<Author> authors;
public class Publisher {
    private Integer id;
    private String name;
    private String address;
    @OneToMany(mappedBy = "publisher")
    private List<Book> books;

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:


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<Author> getAuthorsByLastName(String lastName) {
    String queryString = "SELECT a FROM Author a " +
                         "WHERE a.lastName IS NULL OR LOWER(a.lastName) = LOWER(:lastName)";

    TypedQuery<Author> query = getEntityManager.createQuery(queryString, Author.class);
    query.setParameter("lastName", lastName);
    return query.getResultList;

Hibernate Query Language

JPQL is based on the Hibernate Query Language (HQL), an earlier non-standard query language included in the Hibernate object-relational mapping library.

Hibernate and the HQL were created before the JPA specification. As of Hibernate 3 JPQL is a subset of HQL.

See also

External links

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at Create an account using LinkedIn to manage and organize your omni-channel knowledge. is like a shopping cart for information -- helping you to save, discuss and share.

  Contact Us