When do and when do I not need to manually persist updates to a JPA entity
<p>I have an java.persistence.Entity class, that I instantiate and persist using java.persistence.EntityManager.persist. For safety I make sure it's merged into the persistence context and I'm good. </p>

<p>Now, I know that when I create the entity from scratch, I need to manually persist it via the EntityManager, but what about if I simply retrieved an already existing record as an entity? My testing indicates that simply calling setters on that entity results in the updates making it to the database, but I'm looking for something definitive to rely on. So please can anyone shed light or a source on when (reliably) do updates to an attached entity get written disk. At this point, I've no choice but to manually persist the entity after making my changes but I rather know when and when I don't have to.</p>

<p>Update:(thanks Yusuf) according to the accepted answer mentioned below, my question is answered. <a href="https://stackoverflow.com/questions/1069992/jpa-entitymanager-why-use-persist-over-merge/1070629#1070629">JPA EntityManager: Why use persist() over merge()?</a>.</p>

<p>According to that answer <em>persist</em> itself does nothing other than add the entity to the persistence context. And merge adds a new object to the context. The implication then is that persistence is simply a function of being part of the persistence context, and since by getting hold of an entity via the entity manager, the entity is attached to the context, so it follows that there is no need at all to call <em>persist</em>. </p>