title: Hibernate collection loaded by custom SQL
body: <p>I have some problems trying to get a bag collection of a class to be loaded through custom sql.
  Here's the xml mappings I have for my class    </p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="alekso.npe.model.Utente" table="VNPEZZ_UTE_MAT" lazy="false"&gt;
      &lt;id name="matricola" column="C_UTE_MAT"&gt;             
      &lt;/id&gt;       
      &lt;property name="nome" column="T_NOM" /&gt;
      &lt;property name="cognome" column="T_COG" /&gt;
      &lt;property name="email" column="T_EML" /&gt;
  
      &lt;bag name="ruoli" table="VNPEZX_UTE_APP_TRN" 
          inverse="false" lazy="true" fetch="select" cascade="all" &gt;
          &lt;key column="C_UTE_MAT" /&gt;
          &lt;one-to-many class="alekso.npe.model.Ruolo" /&gt;
          &lt;loader query-ref="rolesQuery"/&gt;
      &lt;/bag&gt;
  &lt;/class&gt;
      &lt;class name="alekso.npe.model.Ruolo" table="VNPEZH_TIP_USR"
      lazy="false" where="C_APP = 'NPE'"&gt;
      &lt;id name="codice" column="C_TIP_USR"&gt;            
      &lt;/id&gt;   
      &lt;property name="nome" column="T_DES_TIP_USR"/&gt;      
  
  &lt;/class&gt;
  &lt;sql-query name="rolesQuery"&gt;
      &lt;return alias="role" class="alekso.npe.model.Ruolo"&gt;&lt;/return&gt;
      &lt;load-collection alias="ruoli" role="alekso.npe.model.Ruolo" &gt;&lt;/load-collection&gt;
      &lt;![CDATA[select {ruolo.*}
      from NPEA.vnpezx_ute_app_trn permesso join NPEA.vnpezh_tip_usr ruolo
        on ruolo.c_tip_usr = permesso.c_tip_usr
        where permesso.c_app = 'NPE'
        and permesso.c_ute_mat = :matricola ]]&gt;
  &lt;/sql-query&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>But when I run the application I get an error:
  <code>org.hibernate.HibernateException: Errors in named queries: rolesQuery</code> in the buildSessionFactory phase.
  Can you tell me what's wrong with this mapping?
  I tried both with and without the <code>&lt;return&gt;</code> tag inside the <code>&lt;sql-query&gt;</code> but it still don't work</p>