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.

To use an analogy, the domain model annotated with ORM configuration is like a children’s toy ...

Get EJB 3 in Action now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.