javajavax

query.list() Exception java.lang.Integer cannot be cast to java.lang.String


I encounter an error when I'm in javax queries So far I have not encountered such an error and I do not know why

@POST
@Path("/aa")
@Consumes(MediaType.APPLICATION_JSON)
public Response polaki(User user, @HeaderParam("Authorization") String authString, @HeaderParam("API_KEY") String apikey) throws Exception {
    if (authString.equals(UserSetting.Authorization) & apikey.equals(UserSetting.API_KEY)) {
        tx = session.getTransaction();

        tx.begin();
        Query query = session.createQuery("from Service where  service=:service");
        query.setParameter("service", user.getService());
        tx.commit();
        List ls= query.list(); // Eror

        return Response.status(200).entity("{\"message\":\"Service Eror\"}").build();
    } else {
        return Response.status(200).entity("{\"message\":\"Service Eror\"}").build();
    }
}

Exception java.lang.Integer cannot be cast to java.lang.String


Solution

  • What does your user.getService() return? An Integer?

    Try this for example and see what happens:

    query.setParameter("service", String.valueOf(user.getService()));
    

    service is probably a varchar (String-ish) in your database.