title: Calling Stored Procedure and mapping the query result to non-entity POJO using Spring JPA SqlResultSetMapping
body: <p>I am attempting to map the results of a Stored procedure to a non-entity POJO using @SqlResultSetMapping with @ConstructorResult. Here is my code:</p>
  <pre><code>@MappedSuperclass
  @SqlResultSetMapping(name = &quot;Testing&quot;, classes = @ConstructorResult(targetClass = Testing.class, columns = {
          @ColumnResult(name = &quot;TTEAM_ID&quot;, type = Integer.class),
          @ColumnResult(name = &quot;VDATE&quot;, type = BigInteger.class),
          @ColumnResult(name = &quot;Days_in_Field&quot;, type = Integer.class),
          @ColumnResult(name = &quot;Expected_cummilative_Number_of_HH&quot;, type = Integer.class),
          @ColumnResult(name = &quot;Cummlative_HH_Reached&quot;,type = Integer.class),
          @ColumnResult(name = &quot;HH_Reached_for_day&quot;,type = Integer.class),
          @ColumnResult(name = &quot;HHs_Finalised_for_day&quot;, type = Integer.class),
          @ColumnResult(name = &quot;Number_of_HH_in_process_for_day&quot;, type = Integer.class),
          @ColumnResult(name = &quot;Number_of_HH_Refused_for_day&quot;,type = Integer.class),
          @ColumnResult(name = &quot;Number_of_Revisits_Scheduled_for_day&quot;, type = Integer.class),
          @ColumnResult(name = &quot;HH_loss_3rd_visit_attempt_refusals_for_day&quot;, type = Integer.class)}))
  
  public class Testing {
  
      private Integer tteam_id;
      private Integer vdate;
      private Integer days_in_field;
      private Integer Expected_cummilative_Number_of_HH;
      private Integer Cummlative_HH_Reached;
      private Integer HH_Reached_for_day;
      private Integer HHs_Finalised_for_day;
      private Integer Number_of_HH_in_process_for_day;
      private Integer Number_of_HH_Refused_for_day;
      private Integer Number_of_Revisits_Scheduled_for_day;
      private Integer HH_loss_3rd_visit_attempt_refusals_for_day;
  
      public Testing(Integer tteam_id,
                     Integer vdate,
                     Integer Expected_cummilative_Number_of_HH,
                     Integer Cummlative_HH_Reached,
                     Integer HH_Reached_for_day,
                     Integer HHs_Finalised_for_day,
                     Integer Number_of_HH_in_process_for_day,
                     Integer Number_of_HH_Refused_for_day,
                     Integer Number_of_Revisits_Scheduled_for_day,
                     Integer HH_loss_3rd_visit_attempt_refusals_for_day ) {
          this.tteam_id = tteam_id;
          this.vdate = vdate;
          this.Expected_cummilative_Number_of_HH = Expected_cummilative_Number_of_HH;
          this.Cummlative_HH_Reached = Cummlative_HH_Reached;
          this.HH_Reached_for_day = HH_Reached_for_day;
          this.HHs_Finalised_for_day = HHs_Finalised_for_day;
          this.Number_of_HH_in_process_for_day = Number_of_HH_in_process_for_day;
          this.Number_of_HH_Refused_for_day = Number_of_HH_Refused_for_day;
          this.Number_of_Revisits_Scheduled_for_day = Number_of_Revisits_Scheduled_for_day;
          this.HH_loss_3rd_visit_attempt_refusals_for_day = HH_loss_3rd_visit_attempt_refusals_for_day;
      }
  //getter  and setters
  </code></pre>
  <p>and then calling my stored procedure</p>
  <pre><code>public List&lt;Testing&gt; getDailyAchievements(){
          List list;
          StoredProcedureQuery query = entityManager.createStoredProcedureQuery(&quot;dailyreports&quot;, &quot;Testing&quot;);
          try {
              // Execute query
              query.execute();
              list = query.getResultList();
          } finally {
              try {
                  query.unwrap(ProcedureOutputs.class).release();
              } catch (Exception e) {
              }
          }
          return list;
      }
  </code></pre>
  <p>I end up getting the error</p>
  <blockquote>
  <p>Could not locate appropriate constructor on class :
  com.ram.Testing</p>
  </blockquote>
  <p>After trying to debug the application, I end up getting the error</p>
  <blockquote>
  <p>com.microsoft.sqlserver.jdbc.SQLServerException: The statement is
  closed.</p>
  </blockquote>
  <p>I found a couple of resources, including this one: <a href="https://www.javachinna.com/2019/10/26/calling-stored-procedure-and-mapping-the-query-result-to-non-entity-pojo-using-spring-jpa-sqlresultsetmapping/" rel="nofollow noreferrer">@ConstructorResult mapping</a> But I am still not having any luck.</p>
  <p>What am I missing? Why can't the constructor be found?</p>