title: How to force JBoss 4.2.3 to clear hibernate's session cache for every request?
body: <p>It seems to me that JBoss reuses entity managers and the underlying hibernate sessions for multiple requests. I have run a test which proves that in some cases the state of an entity may be out-dated even if it is just fetched using <code>em.find()</code>. </p>
  
  <p>How can I disable this behaviour and force to clear or throw away used sessions to ensure that each request is handled with clear cache?</p>
  
  <p><strong>UPD:</strong></p>
  
  <p>Here is an example case.</p>
  
  <p>HTTP request 1. A session bean creates an entity instance and stores it with field "A" set to value 1. The persisted entity gets ID = 4.</p>
  
  <p>HTTP request 2. A session bean looks up an entity with ID = 4, sets its field "A" to value 2 and saves it.</p>
  
  <p>HTTP request 3. A session bean looks up an entity with ID = 4 and checks it's field "A". If the value is 1 it does one thing, if it is 2 it does another thing.</p>
  
  <p>In case if the EM in request 3 happens to be the same as in request 1, an undesired behavior occurs. I have tested this and got approx. 10% cases of failure.</p>