We noticed a similar behaviour in our system.
And also encountered that writing the query with hardcoded parameters instead of using setParameter()
would fixed the issue.
We are using MS SQL Server and after further investigation we noticed the the root cause of our issue is a default configuration of the sql server driver that transmits the query parameters as unicode. This lead to our indices being ignored since they were based on the ascii values on the queried columns.
The solution was to setup this property in the jdbc url : sendStringParametersAsUnicode=false
See Stackoveflowthis Q&A on Stackoveflow for details.