Ошибки в именованных запросах - Spring Data JPA - PullRequest
0 голосов
/ 09 мая 2019

Я хочу выполнить @NamedNativeQuery. Я выполняю различные типы операций внутри этого запроса. По какой-то причине я получаю ошибки в именованном запросе без какой-либо конкретной причины. У меня есть класс SurveyResponse как:

@NamedNativeQuery( name = "fetchSurveyResponse", 
query = "select query_id, query," + 
"       sum(case when response = 'BothGood' then count else 0 end) as 
both_good," + 
"       sum(case when response = 'BothBad' then count else 0 end) as 
both_bad," + 
" from" + 
" (" + 
" select q.query_id, query, response, COUNT(response) AS 'count'" + 
" from query q" + 
"    join survey_response sr" + 
"        on (q.query_id = sr.query_id)" + 
" where sr.survey_id = ?1" + 
" Group by q.query_id, query, response" + 
" Order by query" + 
" ) AS new_table" + 
" group by query_id, query", resultClass=SurveyResult.class)
@Entity
@Table(name = "survey_response")
public class SurveyResponse {

@Id
private int surveyResponseId;
private int userId;
private int queryId;
private int surveyId;
private String response;

public int getSurveyResponseId() {
    return surveyResponseId;
}
public void setSurveyResponseId(int surveyResponseId) {
    this.surveyResponseId = surveyResponseId;
}
public int getUserId() {
    return userId;
}
public void setUserId(int userId) {
    this.userId = userId;
}
public int getQueryId() {
    return queryId;
}
public void setQueryId(int queryId) {
    this.queryId = queryId;
}
public int getSurveyId() {
    return surveyId;
}
public void setSurveyId(int surveyId) {
    this.surveyId = surveyId;
}
public String getResponse() {
    return response;
}
public void setResponse(String response) {
    this.response = response;
}

}

Мой класс SurveyResult выглядит так:

public class SurveyResult {

private int queryId;
private String query;
private int bothGood;
private int bothBad;

public int getQueryId() {
    return queryId;
}
public void setQueryId(int queryId) {
    this.queryId = queryId;
}
public String getQuery() {
    return query;
}
public void setQuery(String query) {
    this.query = query;
}
public int getBothGood() {
    return bothGood;
}
public void setBothGood(int bothGood) {
    this.bothGood = bothGood;
}
public int getBothBad() {
    return bothBad;
}
public void setBothBad(int bothBad) {
    this.bothBad = bothBad;
}
}

Мой класс репозитория выглядит так:

@Repository
public interface SurveyResponseRepository
    extends JpaRepository<SurveyResponse, Long>, JpaSpecificationExecutor<SurveyResponse> {

@Query(name="fetchSurveyResponse")
public List<SurveyResponse> getSurveyResponses(int surveyId);

}

Может кто-нибудь помочь мне в решении этой ошибки? Благодаря.

...