0

I am getting this error

Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "("
  Position: 26

when I try use following method

Repository

@Query(value = "select new AgendamentoDTO(a.id, a.data, s.nome, p.nome, pro.nome) " + "from agendamento a " + "join pacientes p on p.id = a.paciente_id " + "join profissionais pro on pro.id = a.profissional_id " + "join servico s on s.id = a.servico_id", nativeQuery = true)
    List<AgendamentoDTO> agendamentos3();

DTO

@Data
@NoArgsConstructor
public class AgendamentoDTO {
    private Integer id;
    private String data;
    private String servico;
    private String paciente;
    private String profissional;

    public AgendamentoDTO(Integer id, String paciente, String data, String profissional, String servico) {
        this.id = id;
        this.data = data;
        this.servico = servico;
        this.paciente = paciente;
        this.profissional = profissional;
    }
}

SpringData - 2.7.0

Database - PostgreSQL

3
  • 3
    Isn't the point of nativeQuery = true that the query should be just plain SQL? If so, "select new AgendamentoDTO(a.id, a.data, s.nome, p.nome, pro.nome)" doesn't look appropriate to me. Commented Nov 23, 2022 at 13:45
  • Looks like your list is empty. check the similar post stackoverflow.com/questions/38877775/… Commented Nov 23, 2022 at 13:46
  • Constructing a DTO onl works in JPQL not in SQL. Commented Nov 23, 2022 at 14:02

1 Answer 1

0

Works when I Change to JPQL.

@Query(value = "select new com.tcc.tccbackend.dtos.AgendamentoDTO(a.id, a.data, s.nome, p.nome, pro.nome) " + "from Agendamento a " + "join Paciente p on p.id = a.id " + "join Profissional pro on pro.id = a.id " + "join Servico s on s.id = a.id")
    List<AgendamentoDTO> agendamentos3();
Sign up to request clarification or add additional context in comments.

Comments

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.