Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Chapter 5. The Java Persistence Query Language

EJB 3 provides the Java Persistence Query Language (JPQL). In this chapter we will cover:

  • Projections

  • GROUP BY and HAVING clauses

  • Joins

  • Subqueries

  • Dynamic Queries

  • Functions

  • Queries with parameters

  • Handling Date and Time

  • Bulk update and delete operations

  • Native SQL

Introduction

A rather limited query language, EJB QL, was provided in EJB 2.0 and 2.1. JPQL enhances EJB QL by providing the following features: JOINs, GROUP BY, HAVING, projection, subqueries, dynamic queries, bulk update and delete. We shall see examples of all these features in this chapter.

JPQL is similar to the SQL language for querying relational databases. However, JPQL queries are expressed in Java objects rather than tables and columns. As SQL dialects differ between relational database vendors, JPQL has an added advantage of portability across databases. The entity manager uses the JDBC configuration specified in the persistence.xml file to convert the JPQL query to native SQL.

There...