A removed state marks an entity instance whose database representation is scheduled for deletion by a persistence provider. The instance enters this state after EntityManager.remove() or after removing a mapped collection reference with orphan removal enabled. section 10.1.1
The removal lifecycle has several observable consequences:
- The provider queues deletion until the unit of work completes; transaction commit synchronizes the state transition and executes SQL DELETE. section 10.2.5
- The removed instance is no longer persistent, so EntityManager.contains(instance) returns false. section 10.2.5
- References should normally be discarded after application work, such as rendering a removal-confirmation screen. section 10.1.1
- Hibernate fully initializes a proxy during removal and runs lifecycle callbacks or entity listeners required for the transition. section 10.2.5
Canceling a queued deletion
Item item = em.find(Item.class, ITEM_ID);\nem.remove(item);\nassertFalse(em.contains(item));\nem.persist(item); // cancel before flush\nem.getTransaction().commit(); section 10.2.5
Entity instance states and their transitions provide a compact map of how removal relates to transient, persistent, and detached states. section 10.1.1
