spring SQL中的JAVA错误:“(“位置或其附近出现语法错误:26

3npbholx  于 2022-11-28  发布在  Spring
关注(0)|答案(1)|浏览(131)

我收到此错误

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

尝试使用以下方法时

存储库

@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;
    }
}

Spring数据- 2.7.0
数据库- PostgreSQL

mkshixfv

mkshixfv1#

当我更改为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();

相关问题