intermediateEntity Lifecycle — Persist, Merge, Detach, Remove & Proxies

Why is it a common mistake to keep using the object you passed into merge()?

merge() does NOT make the object you passed in managed — it copies that object's state onto a different, managed entity (looked up or loaded by ID) and returns THAT object. The object you originally passed in remains detached. Continuing to use the original reference, expecting it to now be managed and dirty-checked, is a very common real bug.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to What causes a LazyInitializationException, precisely?← Back to all Spring Data JPA & Hibernate Mastery questions