From the course: Java Persistence API (JPA): 1 The Basics

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Entity life cycle

Entity life cycle - Java Tutorial

From the course: Java Persistence API (JPA): 1 The Basics

Start my 1-month free trial

Entity life cycle

- [Instructor] All entities have a lifecycle with event types that range from loading, persisting, updating, and removing. Let's learn about the lifecycle of entities and how that lifecycle differs from other Java EE components. When we talk about regular Java objects, their lifecycle is straightforward. We create an instance with a new keyword, and the garbage collector removes it when it is no longer used. An entity is an object, so like a regular Java object, it is created with a new keyword and garbage collected. The difference between an entity and a regular Java object is that an entity is managed by the entity manager. An entity has events during its lifecycle, events that range from persisting, updating, removing, and loading. Depending at which stage of the lifecycle the entity is in, it is either considered managed or detached. A managed entity is under the control of the entity manager, and the detached entity is in the final lifecycle state. When an entity is first created…

Contents