Chapter 9. Manipulating entities with EntityManager

 

This chapter covers

  • Persistence context and its scope
  • Container- and application-managed entity managers
  • Entity lifecycle and CRUD operations
  • Detachment and merge operations
  • Entity lifecycle listeners

In chapter 7 you learned how to develop the application domain model using JPA. In chapter 8 you saw how domain objects and relationships are mapped to the database. While the ORM annotations we explored in chapter 8 indicate how an entity is persisted, the annotations don’t do the actual persisting. This is performed by applications using the EntityManager interface, the topic of this chapter.

9.1. Introducing the EntityManager

9.2. Creating EntityManager instances

9.3. Managing persistence operations

9.4. Entity lifecycle listeners

9.5. Entity operations best practices

9.6. Summary