Lesson 32Overview of the Java Persistence API

In the previous lesson you learned about various types of Enterprise Java Beans in which you could program the business logic of your application. Now it’s time to talk about persisting data. If an online store allows users to place orders with session beans, there should be a mechanism for saving the data, too. Typically, the data is persisted in the relational or NoSQL DBMS.

The Java Persistence API (JPA) defines a standard way of mapping the Java classes to their relational database peers. This process is also known as object-relational mapping (ORM). JPA allows you to work with DBMSes using Java objects rather than with SQL. All SQL queries are generated under the hood by the library that implements JPA. The most popular implementation of JPA is Hibernate, and there is a reference implementation called EclipseLink. You use EclipseLink in the “Try It” section of this lesson.

This lesson is a brief introduction to the standard JPA 2.1 that’s implemented by Java EE 7-compliant servers. You’ll also get familiar with the data validation process offered by the Bean Validation framework. 

The Big Picture

In the past, J2EE (currently Java EE) specifications recommended using Entity EJB to provide all interactions with databases. Entity beans have been pruned from the current Java EE specification, and you should use JPA instead to deal with your application’s data querying and persistence. As a matter of fact, you can use JPA from ...

Get Java Programming 24-Hour Trainer, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.