-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: JPA, SQL Server 2005 and unicode characters
PostPosted: Wed Nov 07, 2007 6:45 pm 
Newbie

Joined: Tue Sep 18, 2007 6:14 pm
Posts: 3
Hibernate version:3.2.1.ga
Spring version:2.0.6

and JPA.

Hi,

My application is working with unicode data and at times I need to do string comparisons with unicode data. According to the Microsoft documentation I need to prefix unicode string literals with N

For example
select * from places where places.neighbourhood in ('Dōngchéng')

needs to be
select * from places where places.neighbourhood in (N'Dōngchéng')


unfortunately when I attempt put this literal into the JPA query string I get the following error:

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 'city centre' near line 1, column 148 [SELECT poi from au.com.worldguide.model.Poi poi WHERE poi.destination.id = ? AND poi.poiType.id = ? AND poi.addressNeighbourhood IN (N'city centre', N'CBD', N'Neighbourhood', N'Darlinghurst', N'Paddington') ]; nested exception is java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 'city centre' near line 1, column 148 [SELECT poi from au.com.worldguide.model.Poi poi WHERE poi.destination.id = ? AND poi.poiType.id = ? AND poi.addressNeighbourhood IN (N'city centre', N'CBD', N'Neighbourhood', N'Darlinghurst', N'Paddington') ]
Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 'city centre' near line 1, column 148 [SELECT poi from au.com.worldguide.model.Poi poi WHERE poi.destination.id = ? AND poi.poiType.id = ? AND poi.addressNeighbourhood IN (N'city centre', N'CBD', N'Neighbourhood', N'Darlinghurst', N'Paddington') ]

It appears to have an issue with the N, is there anyway around this?

I must be missing something...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 1:39 am 
Newbie

Joined: Tue Sep 18, 2007 6:14 pm
Posts: 3
Okay I've solved my problem,

I was manually constructing the "in" clause using code similar to the following:
queryString.append("select * from places where neighborhood in (");
for (string string: Neighborhoods)
{
queryString.append("'"string+"', ");
}
queryString.append(")";

(note that's not the code I was using, but you should get the gist).

anyway I've since updated my code to pass all the variables used within the query as query parameters which has resolved my problem.

This was a valuable lesson for me, send everything down to the database as a query parameter.

:)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.