How to resolve? No converter found capable of Converting from type [java.lang.String] to type [@org.springframework.data.jpa.Repository.Query]

Asked

Viewed 2,620 times

2

So Guys I’m having a problem when performing a query through a @query, well basically what I need is a list of a status column in the bd that returns only students who are with the status "Finished" for this I wrote the following query @Query("select p.status from Aluno p where p.status = 'Concluido' ") at first I had no problem, but when I went to view Hibernate released this exception.

Failed to convert from type [java.util.ArrayList] to type [@org.springframework.data.jpa.repository.Query java.util.List] for value '[Concluido]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.string] to type [@org.springframework.data.jpa.Repository.Query com.academy.model.Student] org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList] to type [@org.springframework.data.jpa.repository.Query java.util.List] for value '[Concluido]'; nested Exception is org.springframework.core.convert.Converternotfoundexception: No converter found capable of Converting from type [java.lang.String] to type [@org.springframework.data.jpa.Repository.Query com.academy.model.Student]

Class:

@Entity

public class Student{

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String nome;
private String curso;
private String idade;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date dataCadastro;
@Column(name = "Turno")
private String horario;
private String status;
private String tel;
@Column(name = "telefone_alternativo")
private String telAlt;

// Getters and Setters

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}
public String getNome() {
    return nome;
}
public void setNome(String nome) {
    this.nome = nome;
}
public String getCurso() {
    return curso;
}
public void setCurso(String curso) {
    this.curso = curso;
}

public String getIdade() {
    return idade;
}
public void setIdade(String idade) {
    this.idade = idade;
}
public Date getDataCadastro() {
    return dataCadastro;
}
public void setDataCadastro(Date dataCadastro) {
    this.dataCadastro = dataCadastro;
}
public String getHorario() {
    return horario;
}
public void setHorario(String horario) {
    this.horario = horario;
}
public String getTel() {
    return tel;
}
public void setTel(String tel) {
    this.tel = tel;
}
public String getTelAlt() {
    return telAlt;
}
public void setTelAlt(String telAlt) {
    this.telAlt = telAlt;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

}

2 answers

0

I don’t know if this is your case but I was having a mistake, I modified my:

@Query("SELECT clientes.cod_cliente, clientes.nome FROM Clientes clientes")

I modified it to:

@Query(value = "SELECT clientes.cod_cliente, clientes.nome FROM Clientes clientes", nativeQuery = true)

and it worked properly, this second @Query I say is a native Sql query.

0

You are having problems with the serialization of the data. Jackson is in charge of this through Reflection. To solve this case, you need to create a DTO to serialize the data you really need. You can use Standard Project Converter or Adapter to perform data conversion and do manual serialization.

Another way is to create a value object in which Jackon would serialize for you. For example:

class AlunoStatusVO {
   String status
}

This value, you would return in the serialization of JPA through Jackson.

Note: I am seeing some way for Jackson to take care of it. I will probably change this question if I find some solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.