Chapter 33
Introduction to 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 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). One of the popular third-party ORM frameworks, Hibernate, will be introduced in Lesson 36, but this lesson is a brief introduction to the standard JPA 2.0 implemented by any Java EE 6–compliant server.
The Big Picture
In the past, J2EE specifications recommend using Entity EJB to provide all interactions with databases. Currently, entity beans are undergoing a pruning process, and you should use JPA instead to deal with your application’s data querying and persistence. As a matter of fact, JPA 2.0 can be used from Java SE applications too.
JPA enables you to specify and run queries and update data without needing to write SQL statements as you did in Lesson 22 while studying JDBC.
The Java Persistence API enables you to map Java classes to database tables using metadata and perform create, retrieve, update, and delete (CRUD) operations using Java Persistence Query Language (JPQL), the Persistence ...