JSP - java.lang.IllegalArgumentException: Parameter value [11] did not match expected type [java.lang.Integer (n / a)]

0

SOMEONE CAN SAY WHAT I AM DOING WRONG?

public List<Usuario> obterusuario(String user){

    Consultar consulta = new Consultar ();
    EntityManager obconsulta = consulta.getEntityManager();

    System.out.println("passou"+user);

    String query = "SELECT U FROM CADASTRO_USUARIO U WHERE U.USR_CODIGO=:user";

    TypedQuery<Usuario> tq = obconsulta.createQuery(query,Usuario.class);
    tq.setParameter("user", user);

    return tq.getResultList( );
}
    
asked by anonymous 27.11.2017 / 05:36

1 answer

0

In the database, the ID field is like another format that is not String , varchar ). Your user is being passed as String .

The solution would be either you change the method argument to Integer / int , or you do a parse with the Integer class :

Integer realUser;
try {
  realUser = Integer.parseInt(user);
catch(NumberFormatException nfe) {
  //o valor passado não é um número
  realUser = null;
}

Finally, in the statement tq.setParameter you will pass the variable realUser instead of user .

tq.setParameter("user", realUser);

I hope I have helped.

    
27.11.2017 / 13:56