title: Hibernate caching of native SQL queries
body: <p>The following is a snippet of my Hibernate mapping file. We are using a native SQL query that maps to our returned MyCode object. Only a few of the tables specified in the query are actually mapped in Hibernate.</p>
  
  <pre><code>&lt;hibernate-mapping package="a.b.c.d"&gt;
      &lt;class name="MyCode" table="OVERRIDE" schema="SCHEMA1"&gt;
          &lt;id name="myId" type="java.lang.Long"&gt;
              &lt;column name=ID" length="22"/&gt;
              &lt;generator class="assigned"/&gt;
          &lt;/id&gt;
          &lt;property name="myCode" type="java.lang.String"&gt;
              &lt;column name=CD"/&gt;
          &lt;/property&gt;
          &lt;property name="myDescription" type="java.lang.String"&gt;
              &lt;column name="DESC" length="120"/&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  
      &lt;sql-query name="retrieveCodes"&gt;
          &lt;return class="MyCode"/&gt;
          &lt;![CDATA[
          select distinct o.ID, ec.CD, o.DESC
          from SCHEMA1.AEFX aefx, SCHEMA1.EC ec, SCHEMA1.FC fc, SCHEMA1.MYCODE o
          ....
          ....
  </code></pre>
  
  <p>We are wondering about the benefits in adding caching for this query. The relevant data will be updated rarely, but will be read a lot. </p>
  
  <p>I haven't been able to get a definitive answer in the Hibernate documentation regarding the support Hibernate has for these types of queries. I'm guessing that a second level cache will probably not work here, as most of the above tables are not known to Hibernate.
  What is the best option we have with regard to caching for this native query?</p>
  
  <p>Thanks</p>