-4

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

daniu
  • 14,137
  • 4
  • 32
  • 53
aaaaaa
  • 3
  • 2
  • Have you tried debugging? – Beri Sep 12 '17 at 07:35
  • 2
    Welcome to Stack Overflow! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a [mcve]. Use the "edit" link to improve your *question* - do not add more information via comments. Thanks! – GhostCat Sep 12 '17 at 07:35
  • 1
    And: learn to read those messages. Which part of "there is an Integer number, where a String should be" is unclear to you? – GhostCat Sep 12 '17 at 07:36
  • What does `JavaX` do here? It seems like you use `Hibernate` based `JPA`... – Usagi Miyamoto Sep 12 '17 at 07:46

1 Answers1

0

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.

Jack Flamp
  • 1,223
  • 1
  • 16
  • 32