Java Reference
In-Depth Information
BazaarAccount
instances, respectively, but this is very inefficient. You'd perform mul-
tiple roundtrips to the database and thus give the database and network a needless workout.
A better solution is to use the criteria-API
JOIN
functionality. The code sample in the fol-
lowing listing performs four joins.
Listing 11.7. A winning bid using joins to retrieve fields from multiple objects
The code in this listing performs a join of the selected entities and creates a wrapper entity.
A wrapper entity is a synthetic object that's used to encapsulate the fields you're retriev-
ing—it is essentially a data transfer object (DTO). We'll cover wrappers in
section 11.2.6
when we discuss the
SELECT
clause.
The code sample from ActionBazaar used an inner join. To specify an outer join, pass a
JoinType
to the join method.
JoinType
enumerates three types of join:
INNER
(de-
fault),
RIGHT
(outer), and
LEFT
(outer) join types.
Using the join object that's returned from the join method, you can specify an on-condition.
The on-condition takes either an expression or a predicate, both of which are constructed
using the
CriteriaBuilder
. The following is an example of an on-condition: