在Hibernate中设置参数值时指定String类型 [英] Specifying type of String while setting parameter value in Hibernate

查看:59
本文介绍了在Hibernate中设置参数值时指定String类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 ) .

作为一种解决方法,我将 sendStringParametersAsUnicode ODBC连接参数设置为false,这解决了性能问题,但是我希望这应该是指定哪个字符串参数必须为Unicode的方法,而这只是简单的ANSI.细绳.

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.

谢谢.

推荐答案

我不会在Hibernate或其他地方更改任何Issue,因为这不是Point在当前层中所做的.这是一个配置问题,因此当您必须配置连接参数(URL)时,您可以采用不需要任何转换等的可采用的配置",因此只能切换URL

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

例如:

jdbc:sqlserver://localhost\MYSERVER;DatabaseName=MyDB;sendStringParametersAsUnicode=false

如果将数据库切换到服务器MySQL或任何其他SQL Server,则只需更改配置而不是休眠即可.我认为这不是正确的地方.

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..

希望有帮助.

我发现此列表有用:

Vendor              Parameter
-----------------------------------------
JSQLConnect         asciiStringParameters
JTDS                sendStringParametersAsUnicode
DataDirectConnect   sendStringParametersAsUnicode
Microsoft JDBC      sendStringParametersAsUnicode

http://emransharif.blogspot.de/2011/07/performance-issues-with-jdbc-drivers.html

欢呼:)

这篇关于在Hibernate中设置参数值时指定String类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆