JPA architecture

One of the key aspects of the JPA is the entity manager API, which is responsible for providing Create, Read, Update, and Delete (CRUD) functionality. These are the operations that we can perform on an object that we want to persist on to the database.

Beyond this, one of the most important concepts in the persistence tier is queries. We need rich query capability at the database layer. JPA allows us to create queries in a number of different ways. One of these is Java Persistence Query Language (JPQL), which we can think of as an object-oriented version of Structured Query Language (SQL). It is just as powerful, compact, and expressive as SQL.

Another option is criteria queries. These are a bit different to JPQL. For criteria queries, we don't really use a query language (QL) at all. What we do instead is construct queries by writing a very object-oriented, API-style code.

Another possibility is to use native queries. This is where we can use SQL queries if we aren't using ORM constructs. We use the SQL native queries through JPA and we essentially get 80% of the benefits of JPA, even though we are using native SQL. There is also support for stored procedures.

Because JPA is such a high-level API, we can actually use it as a caching layer once we have done ORM mapping. We can cache all of the entities and the JPA has built-in support for caching.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset