Introducing the Java Persistence Query Language

Everyone reading this book should be familiar with SQL queries and how they work. Constructing a simple query against the ttt_company table to retrieve all records would look something like:

select * from ttt_company

Restricting the result set to companies starting with G would look like the following code line:

select * from ttt_company where company_name like "G%"

In JPA, we are dealing with entities and relationships between entities. The Java Persistence Query Language (JPQL) is used to formulate queries in a similar way to SQL. The previously mentioned statement will be written in JPQL as follows:

SELECT c FROM Company c

And the statement that follows is written as such:

SELECT c FROM Company c WHERE ...

Get Enterprise Application Development with Ext JS and Spring now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.