title: Caching in Java EE application
body: <p>I use JBoss AS. I have a long and heavy SQL that run inside the application server. I want to cache the results based on input parameters.</p>
  
  <p>I have a few options here:</p>
  
  <ol>
  <li><p>Use a caching manager and manually putting the results in the cache.</p></li>
  <li><p>Use a caching manager with loader that will "load" the results into cache when there's no results in cache.</p></li>
  </ol>
  
  <p>I don't care for now about replication of the cache to other servers in cluster.</p>
  
  <p>My question is what option should I choose? What are the benefits and drawbacks of each option. (ease of deployment, configuration mess)</p>
  
  <p>Is this can be implemented using JBoss Cache or ehcache or both.</p>
  
  <hr>
  
  <p><strong>Update:</strong>
  I am using hibernate but the results are not entities, they are counters. I need to count all rows that belong to specific category and have specific status. I want that result to be cached.</p>
  
  <p>Should I wrap the results inside an entity? Then, how can I make it work like (materialized?) view in oracle - to be update automatically or by trigger.</p>