Home > front end >  The column name is not valid in springboot
The column name is not valid in springboot

Time:12-31

I wrote native query but I'm getting an error:

The column name covidSymptomId is not valid.

What's wrong?

There are table in mssql

Error picture

CovidSymptom.java

 @Data
 @AllArgsConstructor
 @NoArgsConstructor
 @Entity
 @Table(name="CovidSymptom")
 public class CovidSymptom {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "covidSymptomId")
private int id;

@ManyToOne
@JoinColumn(name = "covidId")
private Covid covidSymptom;

@Column(name = "symptom")
private String symptom;
}

CovidSymptomDao.java

@Query(nativeQuery = true,value = "Select symptom From CovidSymptom GROUP BY symptom order by count(covidSymptomId) desc")
List<CovidSymptom> getMost3SymptomOffCovid();

CodePudding user response:

You need to include all columns that are mapped in your query. So:

Select covidSymptomId, symptom....

CodePudding user response:

I'm not sure why you're getting a column name problem, since your select query returns a list of "symptom"(String), whilst your method provides a list of "CovidSymptom" (Object).

  • Related