title: Hibernate stored procedure result problem
body: <p>I'm trying to call a stored procedure using Hibernate, but I'm getting the following exception all the time:</p>
  
  <pre><code>org.postgresql.util.PSQLException: The column name plan_id was not found in this ResultSet.
  </code></pre>
  
  <p>The stored procedure is added as an auxiliary database object in one hbm.xml (actually this is the only XML mapping file I have, everything else is done with annotations):</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;database-object&gt;
      &lt;create&gt;
  CREATE OR REPLACE FUNCTION copy_plan(p_plan_id bigint, p_plan_for_year varchar, p_copy_pp boolean)
  RETURNS REFCURSOR
  AS $$
  DECLARE
      result REFCURSOR;
      // some more declarations
  BEGIN
      // a lot of logic which works fine
  
      OPEN result FOR 
      SELECT  plans.plan_id as plan_id,
              plans.plan_for_year as plan_for_year, 
              plans.plan_plan_id as plan_plan_id, 
              plans.plan_f_type as plan_f_type, 
              plans.plan_enabled as plan_enabled
      FROM rgt_plans plans WHERE plans.plan_id = v_plan_id;
  
      RETURN result;
  
  END;
  $$ LANGUAGE PLPGSQL
      &lt;/create&gt;
      &lt;drop&gt;DROP FUNCTION copy_plan&lt;/drop&gt;
  &lt;/database-object&gt;
  </code></pre>
  
  <p></p>
  
  <p>The entity class:</p>
  
  <pre><code>@Entity
  @Table(name = "rgt_plans")
  @NamedNativeQueries({ @NamedNativeQuery(name = "copyPlan", query = "select copy_plan(:planId, :newYear, :copy)", resultClass=Plan.class) })
  public class Plan implements Serializable {
  
  private static final long serialVersionUID = -8448579977833577641L;
  
  @Id
  @GeneratedValue(generator = "IdGenerator", strategy = GenerationType.TABLE)
  @TableGenerator(name = "IdGenerator", pkColumnValue = "rgt_plans", table = "Sequence_Table", allocationSize = 1)
  @Column(name = "plan_id", columnDefinition = "int4")
  private Long id;
  
  @Column(name = "plan_for_year")
  @NotNull
  private String forYear;
  
  @Column(name = "plan_plan_id")
  @Basic
  private Long plan_id;
  
  @Column(name = "plan_f_type", length = 1)
  @Basic
  @NotNull
  private String type;
  
  @Column(name = "plan_enabled")
  @Basic
  @NotNull
  private Boolean enabled;
  
  // getters, setters, equals, hashcode
  
  }
  </code></pre>
  
  <p>And thats how I call it from my DAO:</p>
  
  <pre><code>public List&lt;Plan&gt; copyPlan(Long currentPlanId, String newYear, Boolean copy) {
      return this.getHibernateTemplate()
              .findByNamedQueryAndNamedParam("copyPlan",
                      new String[] { "planId", "newYear", "copy" },
                      new Object[] { currentPlanId, newYear, copy });
  
  }
  </code></pre>
  
  <p>As you can see I'm using PostgreSQL 8. Any ideas to why it's not working? I mean I'm returning everything from that table even with labels assiged...</p>