0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

it didn't help me fix the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.