title: Hibernate: Mapping custom column names in stored procedure named query
body: <p>I currently have the following named query that wraps around a stored procedure:-</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;sql-query name="mySp"&gt;
          &lt;return-scalar column="name_first" type="string" /&gt;
          &lt;return-scalar column="name_last" type="string" /&gt;
  
          { call some_sp :param }
      &lt;/sql-query&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>The columns <code>name_first</code> and <code>name_last</code> are the exact column names returned by the stored procedure. I created a bean that contains the same column names so that I can map the queried result into that bean.</p>
  
  <pre><code>public class MyBean {
      private String  name_first;
      private String  name_last;  
  
      ...
  }
  </code></pre>
  
  <p>The Hibernate code that calls the named query and map the result into the bean:-</p>
  
  <pre><code>MyBean myBean = (MyBean) sessionFactory.getCurrentSession()
                          .getNamedQuery("mySp")
                          .setParameter("param", param)
                          .setResultTransformer(Transformers.aliasToBean(MyBean.class))
                          .uniqueResult();
  </code></pre>
  
  <p>All of these work fine, but instead of relying on the column names from the stored procedure, I want to use my own column names in <code>MyBean</code>, for example:-</p>
  
  <pre><code>public class MyBean {
      private String  firstName; // instead of name_first
      private String  lastName;  // instead of name_last  
  
      ...
  }
  </code></pre>
  
  <p>How do I map my column names against the stored procedure's columns in my named query above?</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE</strong> - I added my final solution below.</p>