intermediateJPA & Hibernate Internals253 of 469

persist() vs merge()

Tests whether you know persist() only works on a transient entity and makes it managed in place, while merge() copies state from a detached entity onto a (possibly newly loaded) managed instance and returns that managed copy -- so the original reference you passed in is never the one you should keep using.

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

← Back to all Spring Boot & Microservices questions