Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In the previous chapter, you saw how to query mapped entities. Now you know how to persist, remove, update, and find an entity by its identifier. With JPQL, you can retrieve one or more entities according to certain search criteria with dynamic, static, and native queries. All these actions are carried out by the entity manager—the central piece that manipulates entities and manages their life cycle.
I described the entity life cycle by saying that entities are managed by the entity manager (meaning that they have a persistence identity and are synchronized with the database) or are detached from the database and used as normal POJOs. But the life cycle of an entity is slightly richer. Importantly, JPA allows you to hook in your own business logic when certain events occur on the entity. This business code is then automatically called by the persistence provider using callback methods.