Java Reference
In-Depth Information
11.4. Summary
In this chapter we covered JPQL, the criteria API, and native SQL queries. The three
approaches to querying data in JPA tackle different problems of querying O/R mapping
data. JPQL is a query language with syntax very similar to that of SQL except you work
in objects. It's still a string-based approach, and interacting with it is similar to working
with JDBC's PreparedStatements . The criteria API is completely different—it uses
a meta-model of your JPA entities, enabling you to construct queries using Java code that's
type-safe. Although the code is verbose and not as easy to read, you won't have to worry
about chasing syntax errors at runtime. The final query language support we covered was
native queries. The native query support enables you to use native SQL queries. With the
previous two approaches, JPA converts either the JPQL or criteria query into native SQL.
With native SQL, you skip that step and can use database-specify features. With Java EE
7, you gained the ability to invoke stored procedures from JPA, which opens up even more
opportunities.
In the next chapter we'll transition to CDI—a powerful dependency injection technology
that was introduced with Java EE 6 and continues to be critical in Java EE 7.
Search WWH ::




Custom Search