问题
I wonder if it's possible to control the type of string (unicode or ANSI) while setting parameter value in the queries generated by Hibernate.
The problem is that the most of the tables in my application have varchar/char columns , and these columns are often appear in various filters. However, all queries generated by Hibernate set parameter type to nvarchar/nchar
making all indexes built on varchar columns pretty much unusable (index scan or full table scan instead of index seek/lookups ) .
As a workaround I set sendStringParametersAsUnicode
ODBC connection parameter to false which solved performance issues , but I hope it should be the way to specify which string parameter has to be Unicode, and which is just simple ANSI string.
Thank you.
回答1:
I wont change any Issue in Hibernate or somewhere else because this is not the Point doing this in the current layer. It Is A configuration Issue so when you have to Configure the Connection Parameter (URL) you could have Adoptable Configuration where you do not need any Converions etc. so you can only switch the URL
e.g:
jdbc:sqlserver://localhost\MYSERVER;DatabaseName=MyDB;sendStringParametersAsUnicode=false
if you switch your DB to server MySQL or any other SQL Server so just change the Configuration not the Hibernate. I don't think that this would be the right place..
Hope that helps..
i found this List Helpfull :
Vendor Parameter
-----------------------------------------
JSQLConnect asciiStringParameters
JTDS sendStringParametersAsUnicode
DataDirectConnect sendStringParametersAsUnicode
Microsoft JDBC sendStringParametersAsUnicode
http://emransharif.blogspot.de/2011/07/performance-issues-with-jdbc-drivers.html
cheers :)
来源:https://stackoverflow.com/questions/37528748/specifying-type-of-string-while-setting-parameter-value-in-hibernate