简体   繁体   English

在 Hibernate 中设置参数值时指定字符串的类型

[英]Specifying type of String while setting parameter value in Hibernate

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.我想知道在 Hibernate 生成的查询中设置参数值时是否可以控制字符串的类型(unicode 或 ANSI)。
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.问题是我的应用程序中的大多数表都有 varchar/char 列,并且这些列经常出现在各种过滤器中。 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 ) .但是,Hibernate 生成的所有查询都将参数类型设置为nvarchar/nchar这使得建立在 varchar 列上的所有索引几乎无法使用(索引扫描或全表扫描而不是索引查找/查找)。

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.作为一种解决方法,我将sendStringParametersAsUnicode ODBC 连接参数设置为 false 以解决性能问题,但我希望这应该是指定哪个字符串参数必须是 Unicode 的方法,哪个只是简单的 ANSI 字符串。

Thank you.谢谢你。

I wont change any Issue in Hibernate or somewhere else because this is not the Point doing this in the current layer.我不会在 Hibernate 或其他地方更改任何问题,因为这不是当前层中执行此操作的要点。 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这是一个配置问题,因此当您必须配置连接参数 (URL) 时,您可以使用可采用的配置,其中不需要任何转换等,因此您只能切换 URL

eg:例如:

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.如果您将数据库切换到服务器 MySQL 或任何其他 SQL Server,那么只需更改配置而不是休眠。 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 http://emransharif.blogspot.de/2011/07/performance-issues-with-jdbc-drivers.html

cheers :)欢呼:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM