org.hibernate.hql.internal.ast.QuerySyntaxException: REPORT Table is not mapped

Viewed 369

I have a simple API that expects three parameters and sends a response back, whenever I try to pass the three parameters I end up with an error

org.hibernate.hql.internal.ast.QuerySyntaxException: REPORTS is not mapped [SELECT e FROM REPORTS e WHERE e.country = :country AND e.projectId = :projectId AND e.code = :code]

The Model class

@Entity(name = "REPORTS")
@Table(name = "REPORTS")
public class DashboardModel {
    public String Country;
    public String Project;
    public String HtmlContent;
    public String FileName;
    public String Code;
    public String TeamLead;
    public String Team;
    public DateTime CreateDate;
    public DateTime UpdateDate;

//boiler plate code

My Controller

@GetMapping(path = "/report/reportsheet")
    public ResponseEntity<String> getReportSheet(@RequestParam("country") String country,
                                                      @RequestParam("projectId") String projectId,
                                                      @RequestParam("clusterNumber") String clusterNumber){
        String report = dashboardService.getReport(country,projectId,clusterNumber);
        //String report_ = wallboardService.getStateReportLabelByCountryProjectAndType(country,projectId,reportType);
        return ResponseEntity.status(HttpStatus.OK).body(report);

My Service

 public String getReport(String country,String projectId,String code){

        TypedQuery<DashboardModel> query = entityManager.createQuery(
                "SELECT e FROM REPORTS e WHERE e.country = :country AND e.projectId = :projectId AND e.code = :clusterNumber" , DashboardModel.class);

        List<DashboardModel> dashboard = query
                .setParameter("country", country)
                .setParameter("projectId", projectId)
                .setParameter("clusterNumber", code)
                .getResultList();

        return String.valueOf(dashboard);

    }

How should I map the table correctly?

2 Answers

You have to use entity class names like DashboardModel in the JPQL and a table name REPORTS in the SQL.

The second parameter DashboardModel.class in the createQuery() is not related to entity class name in the SELECT clause. You can just use createQuery(jpql) with one parameter, but that method returns a List without element type. So what the second parameter DashboardModel.class for.

You don't need to specify table name here @Entity(name = "REPORTS")

just @Entity

Related