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

Queries with Relationships


A SELECT clause can refer to persistent relationship fields. For example, in the query

SELECT c.referee FROM Customer c

recall that referee is a persistent variable of type Referee which has a one-to-one relationship with the Referee entity. An example of an JPQL association-field is c.referee. Note that the return type in this query is Referee.

A path expression can be composed from other path expressions if the original path expression evaluates to a single-valued association-field. The query

SELECT c.lastName, c.referee.name FROM Customer c

is legal as the path expression c.referee is a single-valued association-field. The query

SELECT c.accounts FROM Customer c

is illegal as the association-field c.accounts evaluates to a collection.