title: Saving Models in Session
body: <p>I use Martijn's approach for an <code>EntityModel</code>: <a href="http://wicketinaction.com/2008/09/building-a-smart-entitymodel/" rel="nofollow">http://wicketinaction.com/2008/09/building-a-smart-entitymodel/</a></p>
  
  <p>I use the <code>EntityModel</code> for storing data in my custom wicket session.</p>
  
  <pre><code> private IModel&lt;Order&gt; order;
   private IModel&lt;User&gt; user;
  </code></pre>
  
  <p>It's set like this:</p>
  
  <pre><code>getSession().setOrder(new EntityModel&lt;Order&gt;(order));
  </code></pre>
  
  <p>My application is a wizard-like order transaction with about 7, 8 connected pages. In some of the pages a bunch of objects get persisted, but not all. So the use of <code>EntityModel</code> allows me to only store the unpersisted objects in the session while the persisted objects just hold the unique ID.</p>
  
  <p>The problem is that the <code>detach()</code> method is never called because the model isn't in any component.</p>
  
  <ul>
  <li>Is saving models into the session the right approach?</li>
  <li>Do I have to call <code>detach()</code> manually in the session on each model?</li>
  </ul>