Skip to Main Content
Enterprise JavaBeans 3.1, 6th Edition
book

Enterprise JavaBeans 3.1, 6th Edition

by Andrew Lee Rubinger, Bill Burke
September 2010
Intermediate to advanced content levelIntermediate to advanced
766 pages
18h 35m
English
O'Reilly Media, Inc.
Content preview from Enterprise JavaBeans 3.1, 6th Edition

JPA QL

Now that you have a basic understanding of how to work with Query objects, you can learn what features are available to you for creating your own JPA QL queries. JPA QL is expressed in terms of the abstract persistence schema of an entity: its abstract schema name, basic properties, and relationship properties. JPA QL uses the abstract schema names to identify beans, the basic properties to specify values, and the relationship properties to navigate across relationships.

To discuss JPA QL, we will use the relationships defined in Chapter 11.

Abstract Schema Names

The abstract schema name can be defined by metadata, or it can default to a specific value. It defaults to the unqualified name of the entity bean class if the name() attribute is not specified when declaring the @Entity annotation.

In the following example, the @Entity.name() attribute is not specified on the Employee bean class, so Employee is used to reference the entity within JPA QL calls:

@Entity
public class Employee {...}

entityManager.createQuery("SELECT e FROM Employee AS e");

In the following example, since the @Entity.name() attribute is defined, you would reference Employee entities in JPA QL as Emp:

@Entity(name="Emp")
public class Employee {...}

entityManager.createQuery("SELECT e FROM Emp AS e");

Simple Queries

The simplest JPA QL statement has no WHERE clause and only one abstract schema type. For example, you could define a query method to select all Employee beans:

SELECT OBJECT( e ) FROM Employee AS e
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
JavaServer Faces

JavaServer Faces

Hans Bergsten
EJB 3 Developer Guide

EJB 3 Developer Guide

Michael Sikora

Publisher Resources

ISBN: 9781449399139Errata Page