Some JPA queries, especially the ones with a LIKE operator, can run very slow on a SQL server using jTDS.
The issue is in the way the jTDS drivers send the parameter strings to the SQL server. Apparently Java will attempt to send the parameters Unicode by default, and SQL server will translate it to ASCII. It can take some seconds because it changes each column value to Unicode before comparing against your parameter. This means it can't take full advantage of any index on the field leading to much slower performance.
If you add the following parameter sendStringParametersAsUnicode=false to your connection string in the datasource, this conversion step can be skipped and it can speed up the performance of your queries:
jdbc:sqlserver://localhost\SQLEXPRESS;DatabaseName=TESTDB;sendStringParametersAsUnicode=false
Add new comment