a1ex07
a1ex07

Reputation: 37382

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

Upvotes: 2

Views: 5060

Answers (2)

Dc.chen
Dc.chen

Reputation: 91

There are one solution as below: 1.set the config not use the default UNICODE, add the config: sendStringParametersAsUnicode=false. 2.add annotation: org.hibernate.annotations.@Nationalized where your use the N(nvarch, ntext ...) type of column in table.

For my environment: use database org.hibernate.dialect.SQLServer2008Dialect.

Upvotes: 0

neoinwonderland
neoinwonderland

Reputation: 86

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

Upvotes: 1

Related Questions