英文:
Spring Boot Repository Native Query for DTO in Postgresql Issue
问题
我在使用Spring Boot和PostgreSQL时编写DTO的本地查询时遇到了问题。
以下是DTO的定义:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserCommentsResponse {
private String placeName;
private String text;
}
以下是本地查询的定义:
@Query(value="SELECT new com.demo.project.dao.UserCommentsResponse(placeName, text) FROM comment c inner join place p on p.id = c.place_id where customer_id = :id", nativeQuery=true)
List<UserCommentsResponse> getUsersComments(int id);
以下是错误消息:
org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
我该如何修复这个问题?
英文:
I have a problem about writing a native query for dto in Spring Boot with the usage of Postgresql.
Here is the dto shown below.
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserCommentsResponse {
private String placeName;
private String text;
}
Here is the native query shown below.
@Query(value="SELECT new com.demo.project.dao.UserCommentsResponse(placeName, text) FROM comment c inner join place p on p.id = c.place_id where customer_id = :id", nativeQuery=true)
List<UserCommentsResponse> getUsersComments(int id);
Here is the error message shown below.
org.postgresql.util.PSQLException: ERROR: syntax error at or near "."
How can I fix it?
答案1
得分: 1
尝试这个
@Query(value="SELECT UserCommentsResponse(placeName, text) FROM comment c inner join place p on p.id = c.place_id where customer_id = :id", nativeQuery=true)
而不是您原始的查询。
英文:
Try this
@Query(value="SELECT UserCommentsResponse(placeName, text) FROM comment c inner join place p on p.id = c.place_id where customer_id = :id", nativeQuery=true)
instead of your original query
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论