You now understand how ORM solves the static aspects of the object/relational mismatch. With what you know so far, you can create a mapping between Java classes and an SQL schema, solving the structural mismatch problem. As you’ll recall, the paradigm mismatch covers the problems of granularity, inheritance, identity, association, and data navigation. For a deeper review, take a look back at section 1.2.
Beyond that, though, an efficient application solution requires something more: you must investigate strategies for runtime data management. These strategies are crucial to the performance and correct behavior of the applications.
In this chapter, we’ll analyze the lifecycle of entity instances—how an instance becomes persistent, and how it stops being considered persistent—and the method calls and management operations that trigger these transitions. The JPA
EntityManager is the primary interface for accessing data.
Before we look at JPA, let’s start with entity instances, their lifecycle, and the events that trigger a change of state. Although some of this material may be formal, a solid understanding of the persistence lifecycle is essential.