as the title indicate i have a native SQL query in my repository like that
@Repository
public interface BesoinRepository extends CrudRepository<Statistic, Long>{
@Query(value="SELECT etat_besoin AS 'state',COUNT(DISTINCT id) AS 'number' FROM besoin WHERE YEAR(date_creation)=:year GROUP BY etat_besoin ",nativeQuery=true)
List<Object> getStatistic(@Param("year") int year);
}
class statistic
package fr.solinum.management.model;
public class Statistic {
private String state;
private int number;
public String getState() {
return state;
}
public int getNumber() {
return number;
}
}
and this is working ok but i want the return type of getStatistic to be List<Statistic> and without creating the table Statistic in my database since i dont need it. in other word i want only to read from the database and return the result as a class. so what are the changes in the model and in the repository or in the controller or what is the optimal approach for my problem? note that i modified my model class as following to solve that but i dont think that this is the optimal or the good approach.
package fr.solinum.management.model;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "besoin")
public class Statistic {
@Id
private int id;
private String state;
private int number;
public String getState() {
return state;
}
public int getNumber() {
return number;
}
}