I'm using the following code to (attempt to) query a database:
Query query = session.createQuery("from Trace where service = :service");
query.setParameter("service", clientRequest[0]);
Where clientRequest[0] is from an array of Strings and the service variable is a String in my POJO mapped to a VARCHAR(45) in my MySQL database.
When I run this code, Hibernate shows the executed SQL query as:
Hibernate: select trace0_.traceId as traceId0_, trace0_.service as service0_, trace0_.longitude as longitude0_, trace0_.latitude as latitude0_, trace0_.timestamp as timestamp0_ from trace trace0_ where trace0_.service=?
Which leads me to believe that the value of clientRequest[0] is not being set correctly as a parameter.
I have checked that clientRequest[0] contains a valid String, which it does. I've tried other ways of creating a query but none of these have worked, they always show service as '?', while if I use the obvious:
Query query = session.createQuery("from Trace where service = 21");
it naturally gives the correct response of
Hibernate: select trace0_.traceId as traceId0_, trace0_.service as service0_, trace0_.longitude as longitude0_, trace0_.latitude as latitude0_, trace0_.timestamp as timestamp0_ from trace trace0_ where trace0_.service=21
What might be stopping setParamater from working correctly?
It is expected output in logs. Hibernate does not log parameters in query strings. Parameter is correctly set. When parameter is not set, you see exception instead.
If you want to log also values of parameters, some instructions can be found from here.