简体   繁体   中英

The column name is not valid in springboot

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();

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

Select covidSymptomId, symptom....

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM