Kadri
Kadri

Reputation: 41

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

Upvotes: 1

Views: 1684

Answers (2)

Med Cezir
Med Cezir

Reputation: 11

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

Upvotes: 1

SledgeHammer
SledgeHammer

Reputation: 7690

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

Select covidSymptomId, symptom....

Upvotes: 1

Related Questions