Java Reference
In-Depth Information
of this in the next chapter. JPA entities support a full range of relational and OO capabilit-
ies, including relationships between entities, inheritance, and polymorphism.
EntityManager
Entities tell a JPA provider how they map to the database, but they don't persist themselves.
The EntityManager interface reads the ORM metadata for an entity and performs per-
sistence operations. The EntityManager knows how to add entities to the database, up-
date stored entities, and delete and retrieve entities from the database.
Java Persistence Query Language
JPA provides a specialized SQL-like query language called Java Persistence Query Lan-
guage (JPQL) to search for entities saved into the database. With a robust and flexible API
such as JPQL, you won't lose anything by choosing automated persistence instead of hand-
written JDBC. In addition, JPA supports native, database-specific SQL, in the rare cases
where it's worth using.
1.3.2. Contexts and dependency injection for Java EE
Java EE 5 had a basic form of dependency injection that EJB could use. It was called
resource injection and allowed you to inject container resources, such as data sources,
queues, JPA resources, and EJBs, using annotations like @EJB , @Resource , and @Per-
sistenceContext . These resources could be injected into Servlets, JSF backing beans,
and EJB. The problem was that this was very limiting. You weren't able to inject EJB
into Struts or JUnit, and you couldn't inject non-EJB DAOs (data access objects) or helper
classes into EJB.
CDI is a powerful solution to the problem. It provides EJB (as well as all other APIs and
components in the Java EE environment) best-of-breed, next-generation, generic depend-
ency injection and context management services. CDI features include injection, automat-
ic context management, scoping, qualifiers, component naming, producers, disposers, re-
gistry/lookup, stereotypes, interceptors, decorators, and events. Unlike many older depend-
ency injection solutions, CDI is completely type-safe, compact, futuristic, and annotation-
driven. We'll cover CDI in detail in chapter 12 .
Search WWH ::




Custom Search