Calling Stored Procedure and mapping the query result to non-entity POJO using Spring JPA SqlResultSetMapping

1.9k Views Asked by At

I am attempting to map the results of a Stored procedure to a non-entity POJO using @SqlResultSetMapping with @ConstructorResult. Here is my code:

@MappedSuperclass
@SqlResultSetMapping(name = "Testing", classes = @ConstructorResult(targetClass = Testing.class, columns = {
        @ColumnResult(name = "TTEAM_ID", type = Integer.class),
        @ColumnResult(name = "VDATE", type = BigInteger.class),
        @ColumnResult(name = "Days_in_Field", type = Integer.class),
        @ColumnResult(name = "Expected_cummilative_Number_of_HH", type = Integer.class),
        @ColumnResult(name = "Cummlative_HH_Reached",type = Integer.class),
        @ColumnResult(name = "HH_Reached_for_day",type = Integer.class),
        @ColumnResult(name = "HHs_Finalised_for_day", type = Integer.class),
        @ColumnResult(name = "Number_of_HH_in_process_for_day", type = Integer.class),
        @ColumnResult(name = "Number_of_HH_Refused_for_day",type = Integer.class),
        @ColumnResult(name = "Number_of_Revisits_Scheduled_for_day", type = Integer.class),
        @ColumnResult(name = "HH_loss_3rd_visit_attempt_refusals_for_day", 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

and then calling my stored procedure

public List<Testing> getDailyAchievements(){
        List list;
        StoredProcedureQuery query = entityManager.createStoredProcedureQuery("dailyreports", "Testing");
        try {
            // Execute query
            query.execute();
            list = query.getResultList();
        } finally {
            try {
                query.unwrap(ProcedureOutputs.class).release();
            } catch (Exception e) {
            }
        }
        return list;
    }

I end up getting the error

Could not locate appropriate constructor on class : com.ram.Testing

After trying to debug the application, I end up getting the error

com.microsoft.sqlserver.jdbc.SQLServerException: The statement is closed.

I found a couple of resources, including this one: @ConstructorResult mapping But I am still not having any luck.

What am I missing? Why can't the constructor be found?

0

There are 0 best solutions below