A persistence snapshot is a stored copy of an entity’s state captured when Hibernate loads it into the persistence context. During flushing, Hibernate compares the managed entity with that copy; a difference triggers an SQL UPDATE. section 10.2.3
Detecting a changed entity
Item item = em.find(Item.class, ITEM_ID); if (item != null) item.setName("New Name"); Hibernate compares the modified Item with its load-time snapshot during flush and writes the changed state with an UPDATE. section 10.2.3
Snapshots support automatic dirty checking, but they consume memory for every persistent instance and make flushing more expensive because Hibernate compares managed instances with their snapshots. Large persistence contexts can therefore cause memory exhaustion or slow synchronization. section 10.2.3 section 10.2.8
Control snapshot overhead by limiting which entities remain managed:
- Use EntityManager#detach(entity) to remove one instance from the persistence context. section 10.2.8
- Use EntityManager#clear() to detach all managed instances and release the persistence context’s retained state. section 10.2.8
- Use read-only settings when modifications are unnecessary; Hibernate then disables snapshots and dirty checking, so flush does not update the database. section 10.2.8










