Java Reference
In-Depth Information
Note
Keep in mind that a named query is scoped with a persistence unit and therefore must have
a unique name. We recommend that you devise a naming convention for your applications
that will avoid duplicate names for named queries.
This was just a brief introduction to querying entities. With the find , createQuery ,
createNativeQuery , and createStoredProcedureQuery methods on
EntityManager , you can get any entity filled with just about any data from your data-
base that you need. Learning the ins and outs of JPQL, the JPA query language for entities,
will be the topic of the next chapter. You'll learn exactly what you need to do to get the
data you want.
10.4. Summary
In this chapter we covered the EntityManager . You learned how to use the
EntityManager to persist, find, merge, and remove entities—the EntityManager
equivalent of the basic database CRUD operations. We also discussed persistence contexts
and scopes, new/detached objects versus managed objects, and the concept of merging
objects. In addition, we briefly mentioned application-managed EntityManager that
can be used for fine-grained control of persistence and transactions via the EntityMan-
agerFactory . Following the discussion of the EntityManager , we briefly discussed
querying—first discussing static versus dynamic queries and then covering basic JPA quer-
ies with simple JPQL, Criteria API, and native queries.
In the next chapter, we'll cover JPQL in depth. You'll learn the syntax you need to get en-
tities with just the data you want. We'll also cover the Criteria API—a type-safe Java code
approach to querying for entities.
Search WWH ::




Custom Search