title: Hibernate: How to avoid evict/detach on children elements
body: <p>I have a simple ManyToOne relationship between <code>Address</code> and <code>Person</code> entities using Hibernate on an old JavaEE 5 project.</p>
  
  <p>On the Person class:</p>
  
  <pre><code>@ManyToOne
  @Cascade(value = {CascadeType.MERGE, CascadeType.PERSIST})
  private Address address;
  </code></pre>
  
  <p>I'm trying to duplicate one Person record without using <code>clone</code> methods of Java. So I'm retrieving it from the database, calling <code>evict()</code> on the Person entity to detach it from the session, resetting its ID and persisting.</p>
  
  <p>Problem > <code>detached entity passed to persist: Address</code></p>
  
  <p>Why is evict also detaching the Address entity? How can I avoid that? I don't want to create another Address record, I want to use the already existing one that it's supposed to be attached to the session, since I'm not using Cascade.EVICT or Cascade.ALL on the ManyToOne relationship.</p>
  
  <p>Meanwhile, I'm evicting the Person, reattaching the address (find by ID), and then calling the persist. It's working fine like that, just wondering if there's a better solution.</p>