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

Asked

Viewed 3,142 times

0

CAN SOMEONE TELL 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( );
}

1 answer

1

In the database, the field ID is like another format that is not String, (sweep or longtext). Your user is being passed off as String.

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

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

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

tq.setParameter("user", realUser);

I hope I’ve helped.

Browser other questions tagged

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