Java Reference
In-Depth Information
How is JPQL different from SQL?
JPQL operates on classes and objects (entities) in the Java space. SQL operates on tables,
columns, and rows in the database space. Although JPQL and SQL look similar, they oper-
ate in two very different worlds.
The JPQL query parser or processor engine of a persistence provider, as shown in figure
11.1 , translates the JPQL query into native SQL for the database being used by the persist-
ence provider.
Figure 11.1. Each JPQL query is translated to an SQL query by the JPQL query processor and executed by the
database. The query processor is supplied by the JPA provider, most likely the application server vendor.
JPQL looks so much like SQL that it's easy to forget you're looking at JPQL when you're
reviewing source code. Just remember that although JPQL may look like SQL, you'll need
to be aware of the differences discussed in this chapter to effectively use and troubleshoot
JPQL in your programs.
All this talk about JPQL queries has piqued your interest, hasn't it? What do you say to
continuing this line of thinking by going over the types of statements JPQL supports? Then
we'll discuss different elements of a JPQL statement, such as FROM and SELECT clauses,
conditional statements, subqueries, and various types of functions. Finally, we'll take a
look at update and delete statements.
11.1.1. Statement types
JPQL supports three types of statements, as shown in table 11.1 . You can use JPQL to per-
form selects, updates, and deletes in your queries.
Search WWH ::

Custom Search