title: How to make a copy of an object in ebean
body: <p>I am working with play[0] application and I am using ebean[1] as my object-relational mapper.
  We have some models which are "immutable" and we need to clone/copy those every time something is changing.</p>
  
  <p>The actual question is:
  What is the proper way to create a copy of an object that has been retrieved from the orm? And how to handle relations with referencing </p>
  
  <p>We have tried to nullify ids and persist models again, but in this case ebean still keep the relation with previous models.</p>
  
  <pre><code>User user = Ebean.find(User.class, id);
  user.setId(null);
  user.save(); //will not create a copy
  </code></pre>
  
  <p>Also I tried to use Ebean._ebean_createCopy()[2] but this doesn't make a deep copy, I think.</p>
  
  <pre><code>User user = Ebean.find(User.class, id);
  User another = user._ebean_createCopy();
  another.setId(null);
  another.save(); //will create a new user but keeps the old references
  </code></pre>
  
  <ul>
  <li>[0] <a href="http://www.playframework.com/" rel="nofollow">http://www.playframework.com/</a></li>
  <li>[1] <a href="http://www.avaje.org/ebean/introduction.html" rel="nofollow">http://www.avaje.org/ebean/introduction.html</a></li>
  <li>[2] <a href="http://www.avaje.org/static/javadoc/pub/com/avaje/ebean/bean/EntityBean.html#_ebean_createCopy()" rel="nofollow">http://www.avaje.org/static/javadoc/pub/com/avaje/ebean/bean/EntityBean.html#_ebean_createCopy()</a></li>
  </ul>