title: org.hibernate.Session.clear() considered Harmful?
body: <p>This is a design question, concrete code not submitted to protect my bottom.</p>
  
  <p>When working with Hibernate the standard workflow is as follows:</p>
  
  <ol>
  <li>Open Session</li>
  <li>Start Transaction</li>
  <li>Do the business (read and modify data)</li>
  <li>Commit Transaction</li>
  <li>Close Session</li>
  </ol>
  
  <p>with possibly iterations through 2-4.</p>
  
  <p>What are reasonable use cases for Session.clear()?</p>
  
  <p>A: The concrete problem I have is a (big) piece of code which loads and modifies entities, then clear()s the session, essentially throwing away the changes that were made. (The business task to be accomplished does not include modifying the entities, so the code "works").</p>
  
  <p>Seems to me the right design would be to make sure the (big) piece of code does not make changes it does not want to save?</p>
  
  <p>B: I would guess Session.clear() exists for convenience/flexibility, not because it is a good idea to use it.</p>
  
  <p>Have I misunderstood the Hibernate philosophy? </p>
  
  <p>C: Subquestion: Is it a bad idea for framework code to unconditionally clear() the session when a task completes? IMHO, the framework should complain if the session is dirty when a task completes! The session should be closed, seeing as the task is done... (Disregarding performance for the minute)</p>
  
  <p>(Labels A, B and C so you can indicate which part you are answering).</p>