Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 18:43 Go to next message
Esta Chavez is currently offline Esta Chavez
Messages: 2
Registered: May 2013
Junior Member
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 14:53 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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)


James : Wiki : Book : Blog : Twitter
Re: Convert varchar to nvarchar for specific columns only. [message #1058651 is a reply to message #1058621] Tue, 14 May 2013 15:34 Go to previous messageGo to next message
Esta Chavez is currently offline Esta Chavez
Messages: 2
Registered: May 2013
Junior Member
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 14:19 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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.


James : Wiki : Book : Blog : Twitter
Previous Topic:Unmarshalling inheritance based entity failed in WebLogic
Next Topic:Not able to create entity after changing the primary key
Goto Forum:
  


Current Time: Thu Oct 23 02:23:13 GMT 2014

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

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