title: How do you keep clean layers separation with Hibernate/ORM?
body: <p>How is it possible to keep clean layers with Hibernate/ORM (or other ORMs...)?</p>
  
  <p>What I mean by clean layer separation is for exemple to keep all of the <a href="http://en.wikipedia.org/wiki/Hibernate_%28Java%29" rel="noreferrer">Hibernate </a> stuff in the <a href="http://en.wikipedia.org/wiki/Data_access_object" rel="noreferrer">DAO</a> layer.</p>
  
  <p>For example, when creating a big <a href="http://en.wikipedia.org/wiki/Comma-separated_values" rel="noreferrer">CSV</a> export stream, we should often do some Hibernate operations like evict to avoid OutOfMemory... The filling of the outputstream belong to the view, but the evict belongs to the DAO.</p>
  
  <p>What I mean is that we are not supposed to put evict operations in the frontend / service, and neither we are supposed to put business logic in the DAO... Thus what can we do in such situations?</p>
  
  <p>There are many cases where you have to do some stuff like evict, flush, clear, refresh, particularly when you play a bit with transactions, large data or things like that...</p>
  
  <p>So how do you do to keep clear layers separation with an ORM tool like Hibernate? </p>
  
  <hr>
  
  <p>Edit: something I don't like either at work is that we have a custom abstract DAO that permits a service to give an Hibernate criterion as an argument. This is practical, but for me in theory a service that calls this DAO shouldn't be aware of a criterion. I mean, we shouldn't have in any way to import Hibernate stuff into the business / view logic.</p>
  
  <hr>
  
  <p>Is there an answer, simple or otherwise?</p>