Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Convert varchar to nvarchar for specific columns only.
Convert varchar to nvarchar for specific columns only. [message #1058376] Mon, 13 May 2013 14:43 Go to next message
Eclipse UserFriend
I am using EclipseLink and mapping to an existing database. Most of the queries have been written using a CriteriaBuilder and typesafe queries. Everything works pretty well.

The problem is that some indexes are varchar and some are nvarchar. By default all of the string values are sent as unicode. Previously we had used the query string parameter for SqlServer "sendStringParametersAsUnicode=false" which sends all strings as non-unicode by default, then we manually overrode the types for the nvarchar indexes in hibernate to make sure those specific ones were sent correctly. (This is to avoid SQL Server from doing a scan and effectively removing the advantage of the index in the first place)

My question is, is there a way to do the equivalent in EclipseLink? I have tried a SessionCustomizer to override the type for a specific column but it didn't seem to affect the resulting sql statement.

Any advice would be appreciated.


Re: Convert varchar to nvarchar for specific columns only. [message #1058621 is a reply to message #1058376] Tue, 14 May 2013 10:53 Go to previous messageGo to next message
Eclipse UserFriend
sendStringParametersAsUnicode is a JDBC property. It needs to be set on the JDBC connection.

If you are using a DataSource you need to set it in your DataSource options, otherwise you can set it in your persistence.xml.

You can either set it a part of your JDBC URL

i.e.
jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value]

or use the EclipseLink persistence property,

"eclipselink.jdbc.property.sendStringParametersAsUnicode"="false"
(requires EclipseLink 2.4)
Re: Convert varchar to nvarchar for specific columns only. [message #1058651 is a reply to message #1058621] Tue, 14 May 2013 11:34 Go to previous messageGo to next message
Eclipse UserFriend
Sorry, I should have been more specific. I am able to set the "sendStringParametersAsUnicode" property no problem and the value is being honored. This is correctly sending all strings as Unicode or non-Unicode depending on its value.

The part I can't figure out is how to override that value for specific columns. I need to be able to send both Unicode and non-Unicode strings within a single query.







Re: Convert varchar to nvarchar for specific columns only. [message #1060012 is a reply to message #1058651] Wed, 22 May 2013 10:19 Go to previous message
Eclipse UserFriend
So what do you need to occur in JDBC exactly?

EclipseLink does have some special support for NVARCHAR types for Oracle. Refer to the Oracle9Platform class for how it is done. You may need to do something similar for SQL Server.

If it is as simple as needing to call setNString() instead of setString(), or setObject() with including the type, then you could log a bug for this, it should be something that could be supported. You could probably support it yourself by subclassing the SQLServerPlatform.
Previous Topic:Modelevolution and -migration - My approach
Next Topic:Not able to create entity after changing the primary key
Goto Forum:
  


Current Time: Thu May 15 10:20:33 EDT 2025

Powered by FUDForum. Page generated in 0.03651 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top