Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink - SQL Server - Unicode?(Making EclipseLink to use Unicode)
EclipseLink - SQL Server - Unicode? [message #633029] Fri, 15 October 2010 07:30 Go to next message
David Safranek is currently offline David SafranekFriend
Messages: 6
Registered: October 2010
Junior Member
Hi all,

I am working on a Java/NetBeans project that uses EclipseLink as a persistence provider and Microsoft SQL Server as a database. Unfortunately I am not able to configure String to be stored as NVARCHAR. EclipseLink uses its default type VARCHAR and it does not seem that there would be an easy and clean solution to this.

I have for example tried to provide my own ORM file

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
	xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
	... >
    <type-converter name="Unicode" data-type="NVARCHAR" object-type="String" />
</entity-mappings>


Which is ignored by EclipseLink.

So is there a way how to make EclipseLink to use Unicode? Thanks in advance for advices.
Re: EclipseLink - SQL Server - Unicode? [message #633625 is a reply to message #633029] Mon, 18 October 2010 15:02 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

To influence the DDL in JPA you must set the columnDefinition in the @Column annotation for the field.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Basic_Attribut es#Column_Definition_and_Schema_Generation



James : Wiki : Book : Blog : Twitter
Re: EclipseLink - SQL Server - Unicode? [message #633776 is a reply to message #633625] Tue, 19 October 2010 12:22 Go to previous messageGo to next message
David Safranek is currently offline David SafranekFriend
Messages: 6
Registered: October 2010
Junior Member
Thank you for the suggestion, but this only leads to platform dependent code which cannot be used in my situation since the code should work on different DB engines.

The only workaround I have found was to take the generated DDL file (that one with SQL statements for table creation) and replace VARCHAR with NVARCHAR. Well, deployment of the database has to be done manually but the code seems to work without a problem.

I really cannot believe that such an obvious thing like Unicode which is in Java since its beginning does not work in EclipseLink!? Shocked
Re: EclipseLink - SQL Server - Unicode? [message #633977 is a reply to message #633625] Wed, 20 October 2010 06:47 Go to previous messageGo to next message
David Safranek is currently offline David SafranekFriend
Messages: 6
Registered: October 2010
Junior Member
Thank you for your suggestion. Unfortunately, this solution is platform dependent which is not acceptable in my situation since the product has to be independent on DB engine.

The only workaround I have found was to take the generated DDL file, replace VERCHAR with NVARCHAR and do the deployment manually. It looks that the EclipseLink does not see any difference so everything works fine.

Actually, it surprises me that EclipseLink does not provide any clean solution to Unicode, which is in Java since its beginning?! I would really like to know if anyone managed it to configure the EclipseLink in non ANSI environments?
Re: EclipseLink - SQL Server - Unicode? [message #634445 is a reply to message #633776] Thu, 21 October 2010 18:04 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

JPA defines the columnDefinition explicitly to supports types such as this. Given it works, it seems a little odd to be saying EclipseLink does not support this.

If you cannot set the columnDefinition, then you could use a DescriptorCustomizer, or SessionCustomizer to set the columnDefinition on the mapping's DatabaseField based on the Session's DatabasePlatform.

You could also modify, or create your own DatabasePlatform subclass to change all VARCHAR to NVARCHAR if you wish.


James : Wiki : Book : Blog : Twitter
Previous Topic:embedded object: field does not exist
Next Topic:Two-tier application: Turn off entire cache
Goto Forum:
  


Current Time: Sat Dec 20 23:02:39 GMT 2014

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

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