Specifying type of String while setting parameter value in Hibernate

匆匆过客 提交于 2021-01-27 19:08:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!