Hibernate: merge returns a copy, and the object you passed in stays detached

merge() does not attach the instance you gave it. It copies the state onto a managed instance and returns THAT - so writes to your original after the call are silently discarded.

Full code & output

This topic is available to PRO members.

Sign in Create a free account

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25